0% found this document useful (0 votes)
19 views29 pages

Shrawani

The document contains a series of Python programming exercises that cover various topics such as calculating averages and percentages, compound interest, month names, commissions based on sales, basic arithmetic operations, leap year checks, area and perimeter calculations, Fibonacci series, multiples of a number, divisibility checks, finding largest and smallest elements in lists, summing even numbers, and working with dictionaries for states and capitals as well as student grades. Each exercise includes source code, input/output examples, and explanations of the logic used. The exercises are designed to help learners practice and reinforce their programming skills.

Uploaded by

trishalad851
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views29 pages

Shrawani

The document contains a series of Python programming exercises that cover various topics such as calculating averages and percentages, compound interest, month names, commissions based on sales, basic arithmetic operations, leap year checks, area and perimeter calculations, Fibonacci series, multiples of a number, divisibility checks, finding largest and smallest elements in lists, summing even numbers, and working with dictionaries for states and capitals as well as student grades. Each exercise includes source code, input/output examples, and explanations of the logic used. The exercises are designed to help learners practice and reinforce their programming skills.

Uploaded by

trishalad851
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 29

#Q1.Write a program that accepts marks in five subjects and display percentage and average.

Source code:

a=int(input(“Enter marks in science:”))

b=int(input(“Enter marks in english:”))

c=int(input(“Enter marks in hindi:”))

d=int(input(“Enter marks in maths:”))

e=int(input(“Enter marks in computer:”))

avg=(a+b+c+d+e)/5

per=((a+b+c+d+e)*100)/100

print("Average is",avg)

print("Percentage is",per)
Input/Output:

Enter marks in science:56

Enter marks in english:66

Enter marks in hindi:78

Enter marks in maths:70

Enter marks in computer:77

Average of marks is 69.4

Percentage is 69.4
#Q2.Write a python program to calculate compound amount and compound interest, where
principal (in rupee),rate of interest( annually) and time taken (in year) is given.

Source code:

principal=float(input("Enter principal amount:"))

rate=float(input("Enter rate of interest:"))

time=float(input("Enter time in years:"))

comp_amount=principal*(1+rate/100)**time

comp_interest=comp_amount-principal

print("Compound Amount is",comp_amount)

print("Compound interest is",comp_interest)


Input/Output:

Enter principal amount:10000

Enter rate of interest:5

Enter time in years:2

Compound Amount is 11025.0

Compound interest is 1025.0


#Q3.Write a python program to input month number out of 1 to 12 and display corresponding
month name .

Source code:

m=int(input("Enter month number(1-12):"))

months={1:"Jaunuary",2:"February",3:"March",4:"April",5:"May",6:"June",

7:"July",8:"August",9:"September",10:"October",11:"November",12:"December"}

print("The month is:",months[m])


Input/Output:

Enter month number(1-12):5

The month is: May


#Q4. Write a python program based on commission will be calculated on the following criteria.
Condition: If sales done more than or equal to 20000 the commission 15% of the sales done .
Condition:If he sales greater than or equal to 10000 and less than 20000 the commission is
10%.Condition :If sales done is >=5000 and less than 10000 then commission 5% of the sale.

Source code:

sales=float(input("Enter the sales amount:"))

if sales>=20000:

commission=0.15*sales

print("The commission is",commission)

elif sales>=10000:

commission=0.10*sales

print("The commission is",commission)

elif sales>=5000:

commission=0.05*sales

print("The commission is",commission)

else:

commission=0

print("No commission for sales less than 5000")


Input/Output:

Enter the sales amount:8000

The commission is 400.0

Enter the sales amount:0

No commission for sales less than 5000

Enter the sales amount:15000

The commission is 1500.0

Enter the sales amount:22000

The commission is 3300.0


#Q5.Write a program that reads two numbers and an arithmetic operator and displays the
computed result.

Source code:

num=float(input("Enter number 1:"))

num1=float(input("Enter number 2:"))

op=input("Enter operator[+,-,*,/,%]:")

result=0

if op=="+":

result=num+num1

elif op=="-":

result=num-num1

elif op=="*":

result=num*num1

elif op=="/":

result=num/num1

else:

print("Invalid operator")

print(num,op,num1,"=",result)
Input/Output:

Enter number 1:78

Enter number 2:65

Enter operator[+,-,*,/]:+

78.0 + 65.0 = 143.0

Enter number 1:34

Enter number 2:2

Enter operator[+,-,*,/]:*

34.0 * 2.0 = 68.0

Enter number 1:55

Enter number 2:34

Enter operator[+,-,*,/,%]:-

55.0 - 34.0 = 21.0

Enter number 1:32

Enter number 2:8

Enter operator[+,-,*,/,%]:/

32.0 / 8.0 = 4.0

Enter number 1:76

Enter number 2:5

Enter operator[+,-,*,/,%]:%

76.0 % 5.0 = 1.0


#Q6. Write a program to check if the year entered by the user is a leap year or not.

Source code:

yr=int(input("Enter a year:"))

if yr%100==0:

if yr%400==0:

leap=True

else:

leap=False

elif yr%4==0:

leap=True

else:

leap=False

if leap==True:

print(yr,"is a leap year")

else:

print(yr,"is not a leap year")


Input/Output:

Enter a year:2000

2000 is a leap year

Enter a year:1670

1670 is not a leap year


#Q7. Write a program to display a menu for calculating area of a circle or a perimeter of a circle.

Source code:

radius=float(input("Enter radius of a circle:"))

print("1.Calculate Area")

print("2.Calcualte Perimeter")

choice=int(input("Enter your choice(1 or 2):"))

if choice==1:

area=3.14*radius*radius

print("Area of circle with radius",radius,"is",area)

elif choice==2:

perm=2*3.14*radius

print("Perimeter of circle with radius",radius,"is",perm)

else:

print("Invalid choice")
Input/Output:

Enter radius of a circle:3.5

1.Calculate Area

2.Calcualte Perimeter

Enter your choice(1 or 2):2

Perimeter of circle with radius 3.5 is 21.98

Enter radius of a circle:3.5

1.Calculate Area

2.Calcualte Perimeter

Enter your choice(1 or 2):1

Area of circle with radius 3.5 is 38.465

Enter radius of a circle:3

1.Calculate Area

2.Calcualte Perimeter

Enter your choice(1 or 2):3

Invalid choice
#Q8. Write a python program to print Fibonacci series of first 20 elements. The initial elements are 0
112358

Source code:

first=0

second=1

print(first)

print(second)

for a in range(1,19):

third=first+second

print(third)

first,second=second,third
Input/Output:

13

21

34

55

89

144

233

377

610

987

1597

2584

4181
#Q9.Write a python program to print first n multiples of a given number.(using while loop)

Source code:

num=int(input("Enter a number:"))

n=int(input("Enter no. of multiples:"))

count=1

print("The first",n,"multiples of",num,"are:")

while count <=n:

print(num*count)

count+=1
Input/Output:

Enter a number:4

Enter no. of multiples:9

The first 9 multiples of 4 are:

12

16

20

24

28

32

36
#Q10. Write a program to find those numbers which are divisible by 7 as well as 5 between 500 and
700.

Source code:

print("Numbers divisible by 7 and 5 between 500 to 700 are:")

for i in range(500,701):

if (i%7==0)and (i%5==0):

print(i,end=",")
Input/Output:

Numbers divisible by 7 and 5 between 500 to 700 are:

525,560,595,630,665,700,
#Q11. Write a program to print largest and second largest element from the list of numbers.

Source code:

lst=eval(input("Enter list:"))

s=sorted(lst)

print("The largest element",s[-1])

print("The second largest element",s[-2])


Input/Output:

Enter list:[56,88,34,21,12]

The largest element 88

The second largest element 56


#Q12.Write a program to find the minimum element from a list of element along with its index in
the list.

Source code:

lst=eval(input("Enter list:"))

min_ele=lst[0]

min_index=0

for i in range(1,len(lst)):

if lst[i]<min_ele:

min_ele=lst[i]

min_index=i

print("Given list is:",lst)

print("Minimum element is",min_ele,"at index",min_index)


Input/Output:

Enter list:[12,43,5,67,9]

Given list is: [12, 43, 5, 67, 9]

Minimum element is 5 at index 2


#Q13.Write a program which input a list of n number and display sum of each even number given in
the list. Example: in the list[2,3,4,5,6,1] sum of even number is 2+4+6=12.

Source code:

lst=eval(input("Enter a list:"))

sum=0

for i in lst:

if i%2==0:

sum=sum+i

print("Sum of even numbers is",sum)


Input/Output:

Enter a list:[2,3,4,5,6]

Sum of even numbers is 12


#Q14.Write a program to input n number of states and its corresponding capitals of India in a
dictionary, and then display it.

Source code:

d={}

n=int(input("Enter no. of capitals you want:"))

for i in range(n):

state=input("Enter state:")

capital=input("Enter capital:")

d[state]=capital

print("States and their capitals are:")

print(d)
Input/Output:

Enter no. of capitals you want:3

Enter state:maharashtra

Enter capital:mumbai

Enter state:assam

Enter capital:dispur

Enter state:rajasthan

Enter capital:jaipur

States and their capitals are:

{'maharashtra': 'mumbai', 'assam': 'dispur', 'rajasthan': 'jaipur'}


#Q15.Write a program to input n number of student’s name and its corresponding percentage of
marks in a dictionary, and then prepare another dictionary with name and grade pair according to
various criterias. Now display name, percent and grade of each student in three columns.

Source code:

You might also like