0% found this document useful (0 votes)
19 views

Python Programs

The document contains code snippets that demonstrate various Python programming concepts like data types, input/output, conditional statements, loops, functions etc. It includes programs to find area and perimeter of basic shapes, arithmetic operations, voting eligibility, grade calculation and more.

Uploaded by

heavenss2009
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Python Programs

The document contains code snippets that demonstrate various Python programming concepts like data types, input/output, conditional statements, loops, functions etc. It includes programs to find area and perimeter of basic shapes, arithmetic operations, voting eligibility, grade calculation and more.

Uploaded by

heavenss2009
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

print("Hello world")

Hello world

print(100+200)

300

n1=190
n2=79798
n3=n1+n2
print('SUM of the two numbers=',n3)

SUM of the two numbers= 79988

#Wap to accept name of a person and print the same


name=input('Enter name:') # name value is accepted by the program and stored in 'name' variable
print('The entered name is',name) #the name value is printed along with the message (The entered name

Enter name:Smitha
The entered name is Smitha
Code Text

# Wap to accept name of a student,class and section and print the same in multiple lines
n=input('Enter name')
c=input('Enter class')
s=input('Enter section')
print('Entered name is',n)
print('Entered class is',c)
print('Entered section is',s)

Enter nameSmitha
Enter class11
Enter sectionA
Entered name is Smitha
Entered class is 11
Entered section is A

#WAP to accept two numbers and perform addition


n1=int(input('Enter first number')) #First number is accepted by the program converted to integer form
n2=int(input('Enter second number'))#second number is accepted by the pgm converted to integer format
n3=n1+n2 # values in n1 and n2 are added and result is stored in n3
print('The sum=',n3) #Printing sum value stored in n3,along with a message

Enter first number12


Enter second number23
The sum= 35

#WAP to accept two numbers and perform all arithmetic operations


n1=float(input('Enter first number'))
n2=float(input('Enter second number'))
s=n1+n2
d=n1-n2
p=n1*n2
q=n1/n2
fq=n1//n2
m=n1%n2
print('sum=' s)
print( sum= ,s)
print('Difference=',d)
print('Product=',p)
print('Quotient=',q)
print('Floor division value=',fq)
print('Remainder=',m)

Enter first number1


Enter second number2
sum= 3.0
Difference= -1.0
Product= 2.0
Quotient= 0.5
Floor division value= 0.0
Remainder= 1.0

#WAP to accept radius of circle and find circumference and area


r=float(input('Enter radius'))
c=2*3.14*r
area=3.14*r*r
print('AREA=',area)
print('CIRCUMFERENCE=',c)

Enter radius1
AREA= 3.14
CIRCUMFERENCE= 6.28

#WAP to accept length and breadth of rectangle and find perimeter and area
l=float(input('Enter length:'))
b=float(input('Enter breadth:'))
area=l*b
p=2*(l+b)
print('AREA=',area)
print('PERIMETER=',p)

Enter length:10
Enter breadth:2
AREA= 20.0
PERIMETER= 24.0

#WAP to accept marks of 5 subjects(Eng,Maths,Sci,SSt,lang2) and compute total and average marks.
eng=float(input('enter eng marks'))
Maths=float(input('Enter maths marks'))
Sci=float(input('Enter sci marks'))
sst=float(input('Enter sst marks'))
lang2=float(input('Enter 2lang marks'))
t=eng+Maths+Sci+sst+lang2
a=t/5
print('TOTAL=',t)
print('AVERAGE=',a)

enter eng marks100


Enter maths marks100
Enter sci marks100
Enter sst marks100
Enter 2lang marks100
TOTAL= 500.0
AVERAGE= 100.0

#WAP to accept age of a person and check for his voting eligibility
p g p g g y
age=float(input('Enter age'))
if age>=18:
print('The person is eligible to vote')
else:
print('The person is not eligible to vote')

Enter age12
The person is not eligible to vote

#WAP to accept percentage of a student and check for his/her scholarship eligibility.
#percentage above 98-eligible for scholarship,otherwise not eligible
p=float(input('Enter percentage:'))
if p>98:
print('Eligible for scholarship')
else:
print('Not eligible for scholarship')

#WAP to accept marks of 3 subjects (eng,maths,sci)and compute total.if total above 150 he is declared
#Otherwise fail.Print appropriate messages
m1=float(input('Enter eng marks'))
m2=float(input('Enter maths marks'))
m3=float(input('Enter sci marks'))
t=m1+m2+m3
print('TOTAL=',t)
if t>150:
print('PASS!!!')
else:
print('FAIL!!!')

Enter eng marks100


Enter maths marks100
Enter sci marks100
TOTAL= 300.0
PASS!!!

#WAP to accept a number and print positive/negative


n=int(input('Enter number'))
if n<0:
print('No. is negative')
else:
print('No. is positive')

Enter number-20
No. is negative

#WAP to accept a number and identify whether even/odd


n=int(input('Enter a number'))
if n1%2==0:
print('No. is even')
else:
print('No.is odd')

if-elif-else statements of python


if-elif-else is used when the program needs to check for more than 2 conditions
Double-click (or enter) to edit

#WAP to accept a number and print positive/negative/zero


n=int(input('Enter no.'))
if n>0:
print('Positive number')
elif n<0:
print('Negative number')
elif n==0:
print('No. equals zero')

'''WAP to accept average marks scored by a student and implement the following:
Marks Grade
>90 A+
80-90 A
60-80 B
<60 C'''
AvgMarks=float(input('Enter average marks')) #accepting average marks
if AvgMarks>90: #checking whether marks is greater than 90
print('GRADE =A+') #if so,A+ will be displayed
elif AvgMarks>=80 and AvgMarks<=90: #checking whether marks between 80 and 90
print('GRADE=A') #Grade A will be displayed
elif AvgMarks>=60 and AvgMarks<80: #checking whether marks between 60-80
print('GRADE=B') #Grade B is displayed
elif AvgMarks<60: #checking whether marks less than 60
print('GRADE=C') #Grade c is displayed

Enter average marks56


GRADE=C

'''WAP to accept total bill of a shop and give discounts as per the given criteria
Bill amount discount%
above 10000 10%
5000-10000 5%
less than 5000 2%
display the discount amount and final net amount'''
bill=float(input('Enter bill amount'))
if bill>10000:
d=0.1*bill
elif bill>=5000 and bill<=10000:
d=0.05*bill
elif bill<5000:
d=0.02*bill
print('discount amount=',d)
net=bill-d
print('net amount=',net)

Enter bill amount15000


discount amount= 1500.0
net amount= 13500.0

'''WAP to accept total bill of a shop and give discounts as per the given criteria
Mode of payment discount%
cash 10%
credit card No discount
Debit card 5%
display the discount amount and final net amount'''
bill=float(input('Enter bill amount'))
mode=input('enter c for cash/cr for credit card/d for debit card:')
if mode=='c':
d=0.1*bill
elif mode=='cr':
d=0
elif mode=='d':
d=0.05*bill
print('discount amount=',d)
net=bill-d
print('net amount=',net)

Enter bill amount80000


enter c for cash/cr for credit card/d for debit card:c
discount amount= 8000.0
net amount= 72000.0

#Write a menu driven program to accept a choice(1/2/3) and find area of circle,rectangle and triangle.
print('MENU')
print('1.AREA OF CIRCLE')
print('2.AREA OF RECTANGLE')
print('3.AREA OF TRIANGLE')
choice=int(input('Enter choice 1/2/3:'))
if choice==1:
r=float(input('Enter radius'))
area=3.14*r*r
print('AREA OF CIRCLE=',area)
elif choice==2:
l=float(input('Enter length'))
b=float(input('Enter breadth'))
area=l*b
print('AREA OF RECTANGLE=',area)
elif choice==3:
b=float(input('Enter base'))
h=float(input('Enter height'))
area=0.5*l*b
print('AREA OF TRIANGLE=',area)
else:
print('Invalid choice!!!Please enter 1/2/3')

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy