Python Programmes
Python Programmes
[3] Create a list of height of 5 students and print the list. (Use mixed
numbers integer and decimal both)
[4] Create a list of first letter of your friends names and print the list.
[5] Write some lines about “Bharat is best” and make list of words used
in the input.
[6] Create a list named friends and include elements like name, date of
birth, lucky number, favorite colour, weight, and height.
[7] Calculate the total number of zeros, positive and negative elements in
the list.
[9] Find out the difference between maximum and minimum elements of
the list.
[12] Read a number from the keyboard and check whether the entered
number is present or not in the list. If present, then also print the
occurrences of a entered number.
[15] Find out the total number of even elements in the list.
[16] Find out the total number of odd elements in the list.
[21] Return the largest even number from the list, if there no even
number in the input, print “Even not found in the list”.
[22] Find the sum of even indexed elements from the list.
[23] Find the product of odd indexed elements from the list.
[24] Write a program to take in the roll number, name and percentage of
marks for n students of Class XI and do the following:
[25] Create a list with some duplicate values and Remove all the
duplicates from the list.
[26] Create a list and check whether your list is having any element or
empty.
[27] Create a list and count the number of strings where the string length
is 2 or more and the first and last character are same from a given list of
strings.
[29] Write a Python program to print a specified list after removing the
0th, 3rd and 5th elements.
[30] Print your list after removing all elements which are divided by 3.
1 Write a python program to find average and grade for given marks.
2 Write a python program to find the sale price of an item with a given cost and discount (%).
5 Write a program to calculate profit-loss for a given Cost and Sell Price.
1
Write a program to find the sum of squares of the first 100 natural numbers.
0
1
Write a program to print the first ‘n’ multiples of a given number.
1
1
Write a program to count the number of vowels in a user-entered string.
2
1 Write a program to print the words starting with a particular alphabet in a user-entered
3 string.
1
Create a dictionary of students to store names and marks obtained in 5 subjects.
4
1
Create a dictionary to store the names of states and their capitals.
5
1. Reverse the entered number by printing the remainder.
2. Reverse the entered number. (Do not print the remainder)
3. Sum of each digit from a number.
9. Sum of series
[22] To compute the sum of the digits of a given positive integer number.
[23] To read any five real numbers and print the average value.
[27] 1 [28] 1
1 2 2 1
1 2 3 3 2 1
1 2 3 4 4 3 2 1
1 2 3 4 5 5 4 3 2 1
[29] 1 [30] 1
2 2 2 2
3 3 3 3 3 3
4 4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5 5
[31] 1 [32] 1
2 2 1 2
3 3 3 1 2 3
4 4 4 4 1 2 3 4
[33] 5 5 5 5 5 [34] a
4 4 4 4 b b
3 3 3 c c c
2 2 d d d d
1 e e e e e
[35] 5 4 3 2 1 [36] 1 2 3 4 5
5 4 3 2 2 3 4 5
5 4 3 1 2 3
5 4 1 2
5 1
[37] A B C D E [38] a b c d e
A B C D a b c d
A B C a b c
A B a b
A a
[39] a [40] *
a b * *
a b c * * *
a b c d * * * *
[41] 1 [42] * *
1 1 * * * *
1 2 1 * * * * * *
1 3 3 1 * * * * * * * *
1 4 6 4 1 * * * * * * * *
[43] * [44] * * * * *
* * * *
* * * * *
* * * * * *
* * * * *
* * * *
* * * * * *
[45] A [46] Z
A B Z Y
A B C Z Y X
A B C D Z Y X W
A B C D E Z Y X W V
A B C D E F Z Y X W V U
[47] A [48] Z
A B Z Y
A B C Z Y X
A B C D Z Y X W
A B C D E Z Y X W V
[49] 1 [50] 1
1 4 4 1
1 4 9 9 4 1
1 4 9 16 16 9 4 1
1 4 9 16 25 25 16 9 4 1
[51] 0 [52] 0
1 0 1 -1 0 1
2 1 0 1 2 -2 -1 0 1 2
3 2 1 0 1 2 3 -3 -2 -1 0 1 2 3
4 3 2 1 0 1 2 3 4 -4 -3 -2 -1 0 1 2 3 4
[53] A diamond pattern is formed with a given letter of the alphabet. Write a
program to generate and display such by accepting any character and total
number of lines (say N). Assume N is an odd number.
V V
V V V
V V V V
V V V
V V
V
[56] Find the value of the following formula : nCr = n!/(r! * (n-r)! )
1. Show record
2. Add new student
3. Delete a student
4. Search record
5. Update record
6. Sort record
7. Exit
Solution:
std={}
for i in range(n):
pn=int(input("Enter Percentage:"))
std[name]=pn
c=0
while c!=7:
print('''
1. Show record
3. Delete a student
4. Search record
5. Update record
6. Sort record
7. Exit
''')
if c==1:
for i in std:
print(i,":",std[i])
elif c==2:
name=input("Enter name:")
pn=int(input("Enter Percentage:"))
std[name]=pn
elif c==3:
f=std.pop(nm,-1)
if f!=-1:
else:
print(f, " not found.")
elif c==4:
if name in std:
else:
elif c==5:
std[name]=pn
elif c==6:
l=sorted(std)
for i in l:
print(i,":",std[i])
elif c==7:
break
else:
print("Invalid Choice")
S.No
Practical Program
.
Write a python program to input two numbers and display the larger /
2
smaller number.
Write a python program to input three numbers and display the largest
3
/ smallest number.
Write a program to input the value of x and n and print the sum of the
following series:
5
1) 1 + x² + x³ + … + xⁿ
2) x – x2/2! + x3/3! – x4/4! + x5/5! – x6/6!
1. 11 + 67
2. 34 + 89 – 34
3. (24 / 2) + (89%4)
4. 11 * 5 – (22 * 2)
5. 25 ** 3 + (26 **3)
6. 23 // 5 % 2
7. 5 < 3
8. 8 > 13
9. 21 < 12 and 5 > 2 or a ==’A’
10.23 != 25 and 26 == 26
3 Write a statement to print your favorite poem in python. Use “\n” to print
the next line. (Without indentation)
5 Write a python statement to repeat the word “Python” three times using a
variable and * operator.
6 Write a python statement to accept your first name, last name, and surname
in three variables and join them using print() function.
7 Write a python statement to display your name and address both in a single
line.
8 Write a statement to print your favorite poem command in python. Use “\n”
to print the next line with a proper indentation.
Algebraic Expression
1. Accept the total score, overs, and find the run rate.
2. Enter the details of 5 players, matches played, runs scored, and print them.
3. Enter two numbers and swap them without taking the temporary variable.
4. Enter a number and power then compute the power using an exponential
operator.
5. Enter two numbers and perform the floor division.
6. Enter two angles of a triangle and find the third angle.
7. Enter any three sides of a rectangle and find the fourth side.
8. Ask the user for the loan amount, rate of interest, and Find the no. of
installments for the year.
Shorthand operators
1. Enter a username, password, and print the message your account has been
created.
2. Enter the money in decimal form and separate them. For example, money
entered is: 100.75 then your output should be 100 Rs. 75 Paise.
3. Conversion programs:
1. Centimeter to Meter and Kilometer
2. Celcius to Fahrenheit
3. Fahrenheit to Celcius
4. Days into Years, Months and weeks
5. Grams to Kilograms
6. Milliliters to liters
4. Generate a series of 1 to n Numbers.
5. Develop a series of odd numbers from 1 to n.
6. Print a series of numbers divisible by 3 from 1 to n.
7. Create a series of square numbers from 1 to n.
8. Display all multiples of 4 starting from 11 to 100.
if-elif-else python exercises Class11
def odd_even():
if n % 2!=0:
print("No is odd")
else:
print("No is even")
odd_even()
def pnz_check():
if n>0:
print("No is positive")
elif n<0:
print("No is negative")
else:
print("Zero")
pnz_check()
[3] The given number is of one digited or two digited or three digited or more
than three digited.
def dig_check():
else:
dig_check()
def smallest4digit():
else:
smallest4digit()
def check_chr():
else:
check_chr()
def check_leapyear():
year = int(input("Enter a character to check:"))
else:
check_leapyear()
def check_div5():
if n%5==0:
else:
check_div5()
def check_max3():
print("No1 is maximum")
elif n2>n1 and n2>n3:
print("No2 is maximum")
print("No3 is maximum")
else:
check_max3()
Do it yourself.
[10] Write a program that reads three positive numbers a, b, c and determines
whether they can form the three sides of a triangle.
def check_3tri():
a=int(input("Enter no1:"))
b=int(input("Enter no2:"))
c=int(input("Enter no3:"))
if(((a+b)<=c)or((b+c)<=a)or((c+a)<=b)):
else:
def check_tritype():
a=int(input("Enter no1:"))
b=int(input("Enter no2:"))
c=int(input("Enter no3:"))
square_a = a**2
square_b = b**2
square_c = c**2
print("Right-angled Triangle")
print("Obtuse-angled Triangle")
else:
print("Acute-angled Triangle")
check_tritype()
[12] If the triangle is an acute angle triangle, determine further whether the
triangle is equilateral, isosceles, or scalene.
def check_tritype2():
a=int(input("Enter no1:"))
b=int(input("Enter no2:"))
c=int(input("Enter no3:"))
if a==b==c:
print("Equilateral triangle")
print("isosceles triangle")
else:
print("Scalene triangle")
check_tritype2()
[13] A toy vendor supplies three types of toys: Battery Based Toys, Key-based
Toys, and Electrical Charging Based Toys. The vendor gives a discount of 10%
on orders for battery-based toys if the order is for more than Rs. 1000. On
orders of more than Rs. 100 for key-based toys, a discount of 5% is given, and
a discount of 10% is given on orders for electrical charging based toys of value
more than Rs. 500. Assume that the numeric codes 1,2 and 3 are used for
battery based toys, key-based toys, and electrical charging based toys
respectively. Write a program that reads the product code and the order
amount and prints out the net amount that the customer is required to pay
after the discount.
def compute_discount():
if opt==1:
if amt>1000:
else:
dis = 0
elif opt==2:
if amt>100:
else:
dis=0
elif opt==3:
if amt>500:
dis = amt*0.1
else:
dis = 0
else:
compute_discount()
= 0, if x = k
Write a program that reads a, b, c, d, k and x and prints the value of f(x).
def sol14():
a = int(input("Enter a:"))
b = int(input("Enter b:"))
c = int(input("Enter c:"))
d = int(input("Enter d:"))
k = int(input("Enter k:"))
x = int(input("Enter x:"))
if x > k:
if x ==k:
fx =0
if x < k:
fx = -a*(x**3) + b**x**2) - c*x + d
print(fx)
sol14()
Read any two positive integer numbers (say n1 & n2) and one character
type operator (say opr). Note that opr is any mathematical operator.
Depending upon the operator, do the appropriate operation. e. g. if opr is
‘+’ then the display the value obtained by evaluating the expression (n1 +
n2).
def sol15():
n1 = int(input("Enter n1:"))
n2 = int(input("Enter n2:"))
if ch=='+':
ans = n1 + n2
elif ch == '-':
ans = n1 - n2
elif ch == '*':
ans = n1 * n2
elif ch == '/':
ans = n1 / n2
else:
print("Invalid choice")
sol15()
Below you will find the list of application based program list for if-elif-
else python exercises Class11.
[16] The Paschim Gujarat Vij Company Ltd. computes the electricity bill based
on the following matrix:
201-300 Rs. 150 plus 1.50 per unit over 200 units
> 300 Rs. 300 plus Rs.2 per unit over 300 units
1. Ask user to enter the Past meter reading and current meter reading.
2. Find the units consumed.
3. Compute the bill according to given matrix.
def sol16():
bill_amt = uc * 0.50
bill_amt = 50 + (uc-100) * 1
else:
sol16()
0-100 – 3% 5%
101-200 5% 8% 10%
1. Ask user to enter the amount and assign following code for the items such
as sh for shorts, p for pans and sht for shirts/t-shirts.
2. Compute the discount and net amount paid by customer.
def sol17():
if opt=='s' opt=='S':
dis = 0
else:
else:
if opt=='t' opt=='T':
else:
sol17()
[18] BSNL has three categories of customers: Industrial, Bulk Institutional and
Domestic. The rates for these are tabulated below :
if cat == "commercial":
elif units>15000:
bill = 1800
elif units>15000:
if cat == "domestic":
bill = 75
bill = units * 2
elif units>300:
print("*"*80)
print("The category:",cat)
print("Units:", units)
print("*"*80)
sol18()
Distance Charges
1-50 8 Rs./Km
51-100 10 Rs./Km
def sol19():
fare = distance * 8
fare = distance * 10
elif distance>100:
fare = distance * 12
else:
print("Invalid fare")
sol19()
[20] The Sardar Patel Cricket Stadium, Motera has the following rates for
different types of seats:
1. Ordinary – 2500
2. Pavillion – 3500
3. Upper Pavillion – 4500
4. Commentary Box – 6000
5. VIP – 8000
They are giving 10% discount for online booking and 8% discount for advance
booking and no discount is given for booking on match day from ticket
window.
1. Ask user to enter the booking type like online, advance or window booking.
2. Ask user to select the types of seats.
3. Compute the amount and print the ticket with proper format.
def sol20():
if s_type=="ordinary":
rate = 2500
elif s_type=="pavallion":
rate = 3500
rate = 4500
rate = 6000
elif s_type=="VIP":
rate = 8000
else:
if b_type=="online":
dis_per = "10%"
elif b_type=="advanced":
dis_per = "8%"
dis = amt * 0.08
elif b_type=="window":
dis_per = "0%"
dis = 0
print("-"*120)
print("-"*120)
print("-"*120)
sol20()