if num > 1:
for i in range(2,num):
if (num % i) == 0:
break
else:
print(num)
Sample output
Enter lower range: 2
Enter upper range: 8
2
3
5
7
Program 76
Write a Python program to change Celsius to Fahrenheit.
Program code
# Python program to convert temperature in Celsius to Fahrenheit
# By Bisakha Pal, Class XI-B, Academic year 2020-2021
Celsius = float(input("Enter any Celsius amount:"))
Fahrenheit = (Celsius * 1.8) + 32
print("The Celsius is ",Celsius, "and", "The Fahrenheit is", Fahrenheit)
Sample output
Enter any Celsius amount: 38
The Celsius is 38.0 and The Fahrenheit is 100.4
Program 77
Write a Python program to change Fahrenheit to Celsius.
Program code
# Python program to convert temperature in Fahrenheit to Celsius
# By Bisakha Pal, Class XI-B, Academic year 2020-2021
temperature = float(input("Please enter temperature in fahrenheit:"))
Celsius = (temperature - 32) * 5 / 9
print("Temperature in celsius: " , Celsius)
51 | P a g e P Y T H O N S N I P P E T S B Y C L A S S 1 1 - B C O M M E R C E S T U D E N T S
Sample output
Please enter temperature in Fahrenheit: 105.0
Temperature in Celsius: 40.55555555555556
Program 78
Write a Python program to find the sum of digits in a number.
Program code
# By Bisakha Pal, Class XI-B, Academic year 2020-2021
# Python program to find sum of digits of a number
n = int(input("Enter a number: "))
sum = 0
while(n!= 0):
rem = n % 10
sum = sum + rem
n = n // 10
print("Sum of digits of is", sum)
Sample output
Enter a number: 6578
Sum of digits of is 26
Program 79
Write a Python program to find the product of two numbers.
Program code
# Python program to print product of two numbers
# By Bisakha Pal, Class XI-B, Academic year 2020-2021
n = int(input("Enter a number: "))
product= 1
while(n!= 0):
rem = n % 10
product= product * rem
n = n // 10
print("Product of digits of is", product)
52 | P a g e P Y T H O N S N I P P E T S B Y C L A S S 1 1 - B C O M M E R C E S T U D E N T S
Sample output
Enter a number: 34235
Product of digits of is 360
Enter a number: 3540
Product of digits of is 0
Program 80
Write a Python program to calculate profit or loss.
Program code
# Python Program to Calculate Profit or Loss
# By Bisakha Pal, Class XI-B, Academic year 2020-2021
actual_cost = float(input("Please Enter the Actual Product Price: "))
sale_amount = float(input("Please Enter the Sales Amount:"))
if(actual_cost > sale_amount):
amount = actual_cost - sale_amount
print("Total Loss Amount ", amount)
elif(sale_amount > actual_cost):
amount = sale_amount - actual_cost
print("Total Profit : ", amount)
else:
print("No Profit No Loss!!")
Sample output
Please Enter the Actual Product Price: 45
Please Enter the Sales Amount:3456
Total Profit : 3411.0
Program 81
Write a Python program to find the Body Mass Index for a person.
Program code
# Python program to print the BMI
# By Bisakha Pal, Class XI-B, Academic year 2020-2021
weight = float(input("Enter weight in kg: "))
height = float(input("Enter height in meters: "))
53 | P a g e P Y T H O N S N I P P E T S B Y C L A S S 1 1 - B C O M M E R C E S T U D E N T S
bmi = weight/(height*height)
print("Your BMI is: " , bmi, end=' ')
if bmi<18.5:
print("Underweight")
elif bmi < 25:
print("Normal")
elif bmi < 30:
print("Overweight")
else:
print("Obesity")
Sample output
Enter weight in kg: 100
Enter height in meters: 1.6
Your BMI is: 39.06249999999999 Obesity
Program 82
Write a Python program to print the calendar.
Program code
# Python program to print the calendar
# By Arthana, Class XI-B, Academic year 2020-2021
import calendar
year = int(input("Enter any year:"))
month=int(input("Enter any month:"))
print(calendar.month(year,month))
Sample output
Enter any year: 2020
Enter any month: 09
September 2020
Mo Tu We Th Fr Sa Su
1 2 34 56
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
54 | P a g e P Y T H O N S N I P P E T S B Y C L A S S 1 1 - B C O M M E R C E S T U D E N T S
Program 83
Write a Python program to get the input from user and find the volume of the
pyramid.
Program code
# Python program to print the volume of the pyramid
# By Arthana, Class XI-B, Academic year 2020-2021
length=float(input("Enter length:"))
width=float(input("Enter width:"))
b=length*width
height=float(input("Enter height:"))
volume=1/3*b*height
print("Volume of pyramid is:" , volume)
Sample output
Enter length: 12.25
Enter width: 10.5
Enter height: 24.5
Volume of pyramid is: 1050.4375
Program 84
Write a Python program to input two numbers and swap them.
Program code
# Python program to swap the values
# By Arthana, Class XI-B, Academic year 2020-2021
n1 = int (input ( "Enter number 1 : "))
n2 = int (input ( "Enter number 2 : "))
print ("Original numbers are:" , n1 ,',' ,n2 )
n1, n2 =n2, n1
print ("After swapping:" , n1,',', n2 )
Sample output
Enter number 1 : 58
Enter number 2 : 45
Original numbers are: 58 , 45
After swapping: 45 , 58
55 | P a g e P Y T H O N S N I P P E T S B Y C L A S S 1 1 - B C O M M E R C E S T U D E N T S
Program 85
Write a Python program to check whether the given character is alphabet or digit.
Program code
# Python program to check alphabet or digit
# By Mohiitha, Class XI-B, Academic year 2020-2021
ch = input("Please Enter any character: ")
if((ch >= 'a' and ch <= 'z') or (ch >= 'A' and ch <= 'Z')):
print("The Character ", ch, "is an Alphabet")
elif(ch >= '0' and ch <= '9'):
print("The Character ", ch, "is a Digit")
else:
print("The Character ", ch, "is Not an Alphabet or a Digit")
Sample output
Please Enter any character: J
The Character J is an Alphabet
Please Enter any character: 5
The Character 5 is a Digit
Please Enter any character: *
The Character * is Not an Alphabet or a Digit
Program 86
Write a program to take N (N > 20) as an input from the user. Print numbers from
11 to N. When the number is a multiple of 3, print “Tipsy”, when it is a multiple of
7, print “Topsy”. When it is a multiple of both, print “TipsyTopsy”.
Program code
# Python program to print the condition as per the condition given
# By Mohiitha, Class XI-B, Academic year 2020-2021
n=int(input("Enter no. greater than 20 : "))
for i in range(11, n+1):
if i%3==0 and i%7==0:
print(i, " InformaticsPractices ")
elif i%7==0:
print(i, "Practices")
56 | P a g e P Y T H O N S N I P P E T S B Y C L A S S 1 1 - B C O M M E R C E S T U D E N T S
elif i%3==0:
print(i, "Informatics")
else:
print(i)
Sample output
Enter no. greater than 20 : 25
11
12 Informatics
13
14 Practices
15 Informatics
16
17
18 Informatics
19
20
21 InformaticsPractices
22
23
24 Informatics
25
Program 87
Write a Python program to Read a Number n and Compute n+nn+nnn
Program code
# Python program to compute n+nn+nnn
# By Elssy, Class XI-B, Academic year 2020-2021
n=int(input("Enter a number n: "))
a=str(n)
t1=a+a
t2=a+a+a
comp=n+int(t1)+int(t2)
print("The value is:",comp)
Sample output
Enter a number n: 5
The value is: 615
57 | P a g e P Y T H O N S N I P P E T S B Y C L A S S 1 1 - B C O M M E R C E S T U D E N T S
Program 88
Write a Python program to take in the marks of 5 subjects and display the grade.
Program code
# Python program to find the grade
# By Mohiitha, Class XI-B, Academic year 2020-2021
sub1=int(input("Enter marks of IP: "))
sub2=int(input("Enter marks of English: "))
sub3=int(input("Enter marks of Economics: "))
sub4=int(input("Enter marks of Accountancy"))
sub5=int(input("Enter marks of BST: "))
avg=(sub1+sub2+sub3+sub4+sub4)/5
if(avg>=90):
print("Grade: A")
elif(avg>=80&avg<90):
print("Grade: B")
elif(avg>=70&avg<80):
print("Grade: C")
elif(avg>=60&avg<70):
print("Grade: D")
else:
print("Grade: F")
Sample output
Enter marks of IP: 100
Enter marks of English: 96
Enter marks of Economics: 89
Enter marks of Accountancy95
Enter marks of BST: 62
Grade: A
Program 89
Write a Python program to find the LCM of numbers.
Program code
# Python program to find the LCM of numbers
# By Sijas, Class XI-B, Academic year 2020-2021
a = float(input("Enter the First Value: "))
58 | P a g e P Y T H O N S N I P P E T S B Y C L A S S 1 1 - B C O M M E R C E S T U D E N T S
b = float(input("Enter the Second Value: "))
if(a > b):
max = a
else:
max = b
while(True):
if(max % a == 0 and max % b == 0):
print("\n LCM of a and b are : ", a,',',b, ',', max)
break;
max = max+ 1
Sample output
Enter the First Value: 15
Enter the Second Value: 20
LCM of a and b are : 15.0 , 20.0 , 60.0
Program 90
Write a Python program to print the natural numbers in reverse order by using while
statement.
Program code
# Python program to print natural numbers in reverse order
# By Mahdi, Class XI-B, Academic year 2020-2021
n= int(input("Enter any Number: "))
i=n
print("List of Natural Numbers in Reverse Order : ", n)
while ( i >= 1):
print (i, end = ' ')
i=i-1
Sample output
Enter any Number: 20
List of Natural Numbers in Reverse Order : 20
20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
59 | P a g e P Y T H O N S N I P P E T S B Y C L A S S 1 1 - B C O M M E R C E S T U D E N T S
Program 91
Write a Python program to print the inverted pattern.
Program code
# Python program to print inverted pattern
# By Jahana, Class XI-B, Academic year 2020-2021
n=int(input("Enter number of rows: "))
for i in range (n,0,-1):
print((n-i) * ' ' + i * '*')
Sample output
Enter number of rows: 6
******
*****
****
***
**
*
Program 92
Write a Python program to get input from user and find quotient and remainder.
Program code
# Python program to find quotient and remainder
# By Aiman, Class XI-B, Academic year 2020-2021
a=int(input("Enter the first number: "))
b=int(input("Enter the second number: "))
quotient=a//b
remainder=a%b
print("Quotient is:",quotient)
print("Remainder is:",remainder)
Sample output
Enter the first number: 54
Enter the second number: 23
Quotient is: 2
Remainder is: 8
60 | P a g e P Y T H O N S N I P P E T S B Y C L A S S 1 1 - B C O M M E R C E S T U D E N T S
Program 93
Write a Python program to count the even numbers and odd numbers in a given
list.
Program code
# Python program to count even and odd numbers
# By Foram, Class XI-B, Academic year 2020-2021
numbers = (1, 34, 55, 3243, 76578, 3123,789, 6745,0, 5)
odd = 0
even = 0
for x in numbers:
if not x % 2:
even+=1
else:
odd+=1
print("Number of even numbers :",even)
print("Number of odd numbers :",odd)
Sample output
Number of even numbers : 3
Number of odd numbers : 7
Program 94
Write a Python program to find the datatype of different data in the list.
Program code
# Python program to check the datatype of the list
# By Nidha, Class XI-B, Academic year 2020-2021
diff_data= [56, 120.658, 345+87j, False, None, 'Pythonsnippet', (1, 4.5, 'p', "IP"), [5, 12,
878, 34], {"class":'XI-B', "Academic year":20202021}]
for a in diff_data:
print ("Type of ",a, " is ", type(a))
Sample output
Type of 56 is <class 'int'>
Type of 120.658 is <class 'float'>
Type of (345+87j) is <class 'complex'>
Type of False is <class 'bool'>
61 | P a g e P Y T H O N S N I P P E T S B Y C L A S S 1 1 - B C O M M E R C E S T U D E N T S
Type of None is <class 'NoneType'>
Type of Pythonsnippet is <class 'str'>
Type of (1, 4.5, 'p', 'IP') is <class 'tuple'>
Type of [5, 12, 878, 34] is <class 'list'>
Type of {'class': 'XI-B', 'Academic year': 20202021} is <class 'dict'>
Program 95
Write a Python program to check the season if month and day are given by the user.
Program code
# Python program to check the season
# By Arthana, Class XI-B, Academic year 2020-2021
m = input("Enter any month: ")
d = int(input("Enter any day: "))
if m in ('January', 'February', 'March'):
season = 'Winter'
elif m in ('April', 'May', 'June'):
season = 'Spring'
elif m in ('July', 'August', 'September'):
season = 'Summer'
else:
season = 'Autumn'
if (m == 'March') and (d > 19):
season = 'Spring'
elif (m == 'June') and (d > 20):
season = 'Summer'
elif (m == 'September') and (d > 21):
season = 'Autumn'
elif (m == 'December') and (d > 20):
season = 'Winter'
print("Season is",season)
Sample output
Enter any month: May
Enter any day: 25
Season is Spring
62 | P a g e P Y T H O N S N I P P E T S B Y C L A S S 1 1 - B C O M M E R C E S T U D E N T S
Program 96
Write a Python program to find the median of three numbers by using if…else
statement.
Program code
# Python program to find median
# By Hayfa, Class XI-B, Academic year 2020-2021
x = float(input("Input first number: "))
y = float(input("Input second number: "))
z = float(input("Input third number: "))
if x > y:
if x < z:
med = x
elif y > c:
med = y
else:
med = z
else:
if x > z:
med = x
elif y < z:
med = y
else:
med = z
print("The median of three numbers is", med)
Sample output
Input first number: 34
Input second number: 21
Input third number: 43
The median of three numbers is 34.0
Program 97
Write a Python program to find the total digits in a given number.
Program code
# Python program to check the total digits in a number
# By Sana, Class XI-B, Academic year 2020-2021
63 | P a g e P Y T H O N S N I P P E T S B Y C L A S S 1 1 - B C O M M E R C E S T U D E N T S
n=int(input("Enter any number:"))
count = 0
while n != 0:
n //= 10
count+= 1
print("Total digits are: ", count)
print(“Thank You!!”)
Sample output
Enter any number: 758928602
Total digits are: 9
Thank You!!
Program 98
Write a Python program to find discount 20% if amount>3000, discount 10% if
amount<=3000 and >1000, otherwise give 5%.
Program code
# Python program to check the discount
# By Saidev, Class XI-B, Academic year 2020-2021
price = float (input("Enter Price :"))
qty = float(input("Enter Quantity :"))
Amt = price* qty
print("Amount :", Amt)
if Amt >3000 :
disc = Amt * .20
print("Discount :", disc)
elif Amt>1000:
disc = Amt * .10
print("Discount :", disc)
else:
disc = Amt * .05
print("Discount :", disc)
Sample output
Enter Price : 1000
Enter Quantity :10
Amount : 10000.0
Discount : 2000.0
64 | P a g e P Y T H O N S N I P P E T S B Y C L A S S 1 1 - B C O M M E R C E S T U D E N T S
Program 99
Write a Python program to print first 10 prime numbers by using for loop.
Program code
# Python program to print first 10 prime numbers
# By Arthana, Class XI-B, Academic year 2020-2021
print("****The first 10 prime numbers ****")
count = 0
n=0
for i in range(1,50) :
count = 0
if n == 10 :
break
for j in range(2,i) :
if i % j == 0 :
count = 1
if count == 0 :
n +=1
print(i)
Sample output
****The first 10 prime numbers ****
1
2
3
5
7
11
13
17
19
23
65 | P a g e P Y T H O N S N I P P E T S B Y C L A S S 1 1 - B C O M M E R C E S T U D E N T S
Program 100
Write a Python program to print the digit and the corresponding name.
Program code
# Python program to print the digit and corresponding name.
# By Harikrishnan, Class XI-B, Academic year 2020-2021
a = int (input ("Enter the digit 1 to 10: "))
if a ==1 :
print ("One ")
elif a ==2 :
print ("Two")
elif a ==3 :
print ("Three")
elif a == 4:
print ("Four ")
elif a == 5:
print ("Five")
elif a == 6:
print ("Six ")
elif a == 7:
print ("Seven")
elif a == 8:
print ("Eight ")
elif a == 9:
print ("Nine")
elif a == 10 :
print ("Ten")
else:
print ("The given digit is out of range ")
Sample output
Enter the digit 1 to 10: 9
Nine
Enter the digit 1 to 10: 69
The given digit is out of range
66 | P a g e P Y T H O N S N I P P E T S B Y C L A S S 1 1 - B C O M M E R C E S T U D E N T S
Copy protecte6d7w| iPthaOgneline-PDP FY-NToH-COopNy.coSmN I P P E T S B Y C L A S S 1 1 - B C O M M E R C E S T U D E N T S