The words you are searching are inside this book. To get more targeted content, please make full-text search by clicking here.
Discover the best professional documents and content resources in AnyFlip Document Base.
Search
Published by judithshalinisam, 2020-11-09 23:04:34

Python Snippet Class XI-B

Python Programs

1|Page PYTHON SNIPPETS BY CLASS 11-B COMMERCE STUDENTS

2|Page PYTHON SNIPPETS BY CLASS 11-B COMMERCE STUDENTS

Table of contents

S.N Program Name P.N

01 Write a Python program that shows the layout for looping statements. 07

02 Write a python program to find the sum of series. 1+1/2+1/3+……..+1/N 07

03 Write a python program to display any multiplication table from 1 to 10. 08

04 Write a python program to obtain temperature of 7 days and then display average 08

temperature of the week.

05 Write a Python program to accept two inputs from the user and perform arithmetic 09

operations by using arithmetic operators.

06 Write a Python program that shows your age when current year and birth year is given as 10

input.

07 Write a Python program that reads a number of seconds and print it in the form: min and 11

seconds.

08 Write a Python program to accept username and password from the user and create a login 12

page by verifying the credentials.

09 Write a Python program to check whether the number present in the given list by using 13

break statement.

10 Write a python program to find Simple Interest and get the principal amount, rate of interest 13

and time from the user.

11 Write a Python program to obtain the input from the user and calculate EMI. 14

12 Write a Python program to accept three integers and print the largest of the three by using 15

if statement.

13 Write a Python program to check whether the given number is odd or even. 15

14 Write a python program to print three numbers in ascending order by using nested if 16

concept.

15 Write a python program to compute the value of Euler’s Number. (Use this formula: e = 1+1/ 17

1! + 1/2! +…………1/n!)

16 Write a program to input any number and to print all-natural numbers up to given number. 17

17 Write a program to input any number and to find sum of all-natural numbers up to given 18

number.

18 Write a Python program to display the pattern by using special characters 18

19 Write a Python program to display the pattern by using numbers. 19

20 Write a Python program to display the pattern. 19

21 Write a Python program to input a value in miles and convert it into kilometers. 20

22 Write a python program to find the five subject’s average marks. 20

23 write a python program to print 5, 10,9 21

24 Write a python program to get an input from the user and find the area of the circle. 21

3|Page PYTHON SNIPPETS BY CLASS 11-B COMMERCE STUDENTS

25 Write a python program to get an input from a user and find the area of the triangle if three 22

sides are given.

26 Write a python program to get an input from a user and find the perimeter of the triangle if 22

three sides are given.

27 Write a Python program to input any string and count how many vowels in it. 23

28 Write a Python program to find the given input is palindrome or not. 23

29 Write a Python program to find the factorial of a given number. 24

30 Write a Python program to check if the number is positive or negative and display an 24

appropriate message.

31 Write a Python program to get any input from the user and check whether the number is 25

less than 100 or not.

32 Write a Python script to display the reverse of a number. 25

33 Write a Python program to check whether the year entered by the user is leap year or not 26

34 Write a Python script to print Fibonacci series’ of first 5 elements. Some initial elements of a 27

Fibonacci series are 0, 1, 1, 2, …

35 Write a Python script to print the sum of natural numbers between 1 to 7. Also, print the 27

sum progressively.

36 Write a Python program to print table of 5. 28

37 Write a Python script to print the odd numbers patterns. 28

38 Write a Python program to find the sum of squares of the first 100 natural numbers. 29

39 Write a Python program to print subject name as character by character. 29

40 Write a python program to print the numbers from 1-25 except the numbers which are 30

divided by 3 and 5 using continue statement.

41 Write a Python program to check the even numbers in the sequence by using pass 31

statement.

42 Write a Python program to check the odd numbers in the sequence by using pass statement. 31

43 Write a python program to print the multiples of 9 till 100 by using pass statement. 32

44 Write a Python program to get the input as list from the user, iterate it and display numbers 33

which are divisible by 5 and if you find number greater than 150 stop the loop iteration.

45 Write a Python program to display the cube of the number up to a given integer. 33

46 Write a Python program to get an input from the user and check whether the person is 34

eligible for voting or not.

47 Write a python program to input any number and check whether the number is a Prime 34

number or not.

48 Write a Python program to find sum of series if ‘n’ is given, s = 1 + x + x2 + x3 + …. + xn . 35

49 Write a Python program to input 3 sides of triangle and print the type of triangle- Equilateral, 36

Scalene, Isosceles.

50 Write a Python program to enter numbers as long as user wishes to enter and find the sum 37

highest and lowest number entered by user.

4|Page PYTHON SNIPPETS BY CLASS 11-B COMMERCE STUDENTS

51 Write a Python program to get input as month from the user and display number of days in 37

that month.

52 Write a Python program to get 3 sides of a triangle and check if these sides will form a 38

triangle or not.

53 Write a Python program to print first N odd numbers in descending order. 39

54 Write a Python program to print the following series: 40

1 8 15 … 40

-1 -8 -15 … -40

55 Write a Python program to print the number of letters in any name. 41

56 Write a Python program to find the length of a side of a cube when Volume is given by the 41

user.

57 Write a Python program to find the square root of a number given by the user. 41

58 Write a Python program to find the radius of a circle when area is given by the user. 42

59 Write a Python program that gives both the Area and Circumference of a circle when R is 42

given by the user.

60 Write a Python program to find speed when distance and time is given by the user. 43

61 Write a Python program to find the area of a parallelogram. 43

62 Write a Python program to find the divisibility of a number with another number. 43

63 Write a Python program which perform arithmetic operations. 44

64 Write a Python program to find the distance when Speed and Time is given by the user. 45

65 Write a Python program to find the volume of a sphere. 46

66 Write a Python program to find death rate in a country if the total death cases are provided 46

by the user.

67 Write a Python program to create voting result finder. 46

68 Write a Python program to find new savings after deducting the interest from the user 47

account.

69 Write a Python program to find the perimeter of a cuboid. 47

70 Write a Python Program to find lowest and second lowest number in a list. 48

71 A store charges Rs.120 per item if you buy less than 10 items. If you buy between 10 and 99 48

items, the cost is Rs.100 per item. If you buy 100 or more items, the cost is Rs.70 per item.

Write a program that asks the user how many items they are buying and prints the total cost.

72 Write a Python script that asks the user to enter a length in centimeters. If the user enters a 49

negative length, the program should tell the user that the entry is invalid. Otherwise, the

program should convert the length to inches and output the result. There are 2.54

centimeters in an inch.

73 Write a program to determine the probability of drawing an ace with the help of Python 49

code.

74 Write a Python program to count the Consonants or Vowels of the given string. 50

75 Write a python to print all prime in a given interval. 50

5|Page PYTHON SNIPPETS BY CLASS 11-B COMMERCE STUDENTS

76 Write a Python program to change Celsius to Fahrenheit. 51
77 Write a Python program to change Fahrenheit to Celsius. 51
78 Write a Python program to find the sum of digits in a number. 52
79 Write a Python program to find the product of two numbers. 52
80 Write a Python program to calculate profit or loss. 53
81 Write a Python program to find the Body Mass Index for a person. 53
82 Write a Python program to print the calendar. 54
83 Write a Python program to get the input from user and find the volume of the pyramid. 55
84 Write a Python program to input two numbers and swap them. 55
85 Write a Python program to check whether the given character is alphabet or digit. 56
86 Write a program to take N (N > 20) as an input from the user. Print numbers from 11 to N. 56

When the number is a multiple of 3, print “Informatics”, when it is a multiple of 7, print 57
“Practices”. When it is a multiple of both, print “InformaticsPractices”. 58
87 Write a Python program to Read a Number n and Compute n+nn+nnn 58
88 Write a Python program to take in the marks of 5 subjects and display the grade. 59
89 Write a Python program to find the LCM of numbers.
90 Write a Python program to print the natural numbers in reverse order by using while 60
statement. 60
91 Write a Python program to print the inverted pattern. 61
92 Write a Python program to find remainder and quotient. 61
93 Write a Python program to count the even numbers and odd numbers in a given list. 62
94 Write a Python program to find the datatype of different data in the list. 63
95 Write a Python program to check the season if month and day are given by the user. 63
96 Write a Python program to find the median of three numbers by using if…else statement. 64
97 Write a Python program to find the total digits in a given number. 65
98 Write a Python program to find the discount rate for the given data. 66
99 Write a Python program to print the digit and the corresponding name.
100 Write a Python program to print first 10 prime numbers by using for loop.

6|Page PYTHON SNIPPETS BY CLASS 11-B COMMERCE STUDENTS

Program 01
Write a Python program that shows the layout for looping statements.
Program code
# Python program to print the layout of all the loops:
# By Karthik V, Class XI-B, Academic year 2020-2021
loop=input ("Enter loop['while' 'While' 'WHILE' 'for' 'For' 'FOR' ] : ")
if (loop== "for") or (loop=="For") or (loop=="FOR"):

print("for[condition]:"
"[statement]")

elif (loop== "while") or (loop== "WHILE") or (loop=="While"):
print("while[condition]:"
'statement')

else:
print("That might not be a type of loop")

Sample output
Enter loop['while' 'While' 'WHILE' 'for' 'For' 'FOR' ] : FOR
for[condition]:[statement]

Enter loop['while' 'While' 'WHILE' 'for' 'For' 'FOR' ] : while
while[condition]:statement

Enter loop['while' 'While' 'WHILE' 'for' 'For' 'FOR' ] : if
That might not be a type of loop

Program 02
Write a python program to find the sum of series.
1+1/2+1/3+……..+1/N
Program code
# Python program to find the sum of the series:
# By Faris, Class XI-B, Academic year 2020-2021
n= int(input("Enter the number:"))
sum= 0

7|Page PYTHON SNIPPETS BY CLASS 11-B COMMERCE STUDENTS

for i in range(1,n+1):
sum= sum +(1/i)

print ("The sum of series is" , sum)
Sample output

Enter the number: 5
The sum of series is 2.283333333333333

Program 03

Write a python program to display any multiplication table from 1 to 10.

Program code

# Python program to display multiplication table from 1 to 10.
# By Omar, Class XI-B, Academic year 2020-2021

num = int(input("Display multiplication table of : "))
for i in range(1, 11):

print(num, 'x', i, '=', num*i)
Sample output

Display multiplication table of : 100
100 x 1 = 100
100 x 2 = 200
100 x 3 = 300
100 x 4 = 400
100 x 5 = 500
100 x 6 = 600
100 x 7 = 700
100 x 8 = 800
100 x 9 = 900
100 x 10 = 1000

Program 04

Write a python program to obtain temperature of 7 days and then display average
temperature of the week.
Program code

# Python program to find the temperature of 7 days and then display
# By Naren Jyothi, Class XI-B, Academic year 2020-2021

8|Page PYTHON SNIPPETS BY CLASS 11-B COMMERCE STUDENTS

m=float(input("Enter the first value: "))
t=float(input("Enter the second value: "))
w=float(input("Enter the third value: "))
th=float(input("Enter the fourth value: "))
f=float(input("Enter the fifth value: "))
s=float(input("Enter the sixth value: "))
su=float(input("Enter the sevens value: "))
Avg_temp=(m+t+w+th+f+s+su)/7
print("Average temperature is : ", Avg_temp)
Sample output

Enter the first value: 23.3
Enter the second value: 32.2
Enter the third value: 35.3
Enter the fourth value: 24.5
Enter the fifth value: 43.5
Enter the sixth value: 32.4
Enter the sevens value: 25.4
Average temperature is : 30.942857142857147

Program 05

Write a Python program to accept two inputs from the user and perform arithmetic
operations by using arithmetic operators.

Program code

# Python program to print two numbers and arithmetic operator
# By Anandu, Class XI B, Academic year 2020-2021
a = int(input("Enter First Number: "))
b = int(input("Enter Second Number: "))
print("Enter which operation would you like to perform?")
op= input("Enter any of these operator for specific operation +,-,*, /, %, //: ")
result = 0
if op == '+':

result = a + b
elif op == '-':

result = a - b
elif op == '*':

result = a * b
elif op == '/':

9|Page PYTHON SNIPPETS BY CLASS 11-B COMMERCE STUDENTS

result = a / b
elif op == '%':

result = a % b
elif op == '//':

result = a // b
else:

print("Input operator is not recognized!")
print(a, op , b, ":", result)
Sample output

Enter First Number: 56
Enter Second Number: 23
Enter which operation would you like to perform?
Enter any of these operator for specific operation +,-,*, /, %, //: /
56 / 23 : 2.4347826086956523

Enter First Number: 40
Enter Second Number: 3
Enter which operation would you like to perform?
Enter any of these operator for specific operation +,-,*, /, %, //: //
40 // 3 : 13

Enter First Number: 43
Enter Second Number: 2
Enter which operation would you like to perform?
Enter any of these operator for specific operation +,-,*, /, %, //: %
43 % 2 : 1

Program 06

Write a Python program that shows your age when current year and birth year is
given as input.
Program code

# Python program to print your age
# By Karthik V, Class XI-B, Academic year 2020-2021
a = int(input("Enter the year you were born: "))
b = int(input("Enter the current year: "))
c = b-a
print("You are ",c," years old now!!! Congrats ")

10 | 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

if c >= 18 and c <60 :
print("You are above 18 years of age ")

elif c >= 60:
print("You are more than 60 years of age")

elif c < 1 :
print("Please enter a valid age")

print("Thank you !!!")
Sample output

Enter the year you were born: 1999
Enter the current year: 2020
You are 21 years old now!!! Congrats
You are above 18 years of age
Thank you !!!

Enter the year you were born: 1986
Enter the current year: 2020
You are 34 years old now!!! Congrats
You are above 18 years of age
Thank you !!!

Enter the year you were born: 2020
Enter the current year: 2020
You are 0 years old now!!! Congrats
Please enter a valid age
Thank you !!!

Program 07

Write a Python program that reads a number of seconds and print it in the form:
min and seconds Eg: 200 seconds are printed as 3 mins and 20 sec.

Program code

# Python program to a number of seconds and print it in for: min and seconds
# By Naren Jyothi , Class XI-B, Academic year 2020-2021
a=int(input("Enter number of seconds: "))
seconds=a//60
minutes=a%60

11 | 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

print ("The Minutes and Seconds are :- ", seconds, ":", minutes)
Sample output

Enter number of seconds: 240
The Minutes and Seconds are :- 4 : 0

Program 08

Write a Python program to accept username and password from the user and create
a login page by verifying the credentials.
Program code

# Python program to display the login page
# By Karthik V, Class XI-B, Academic year 2020-2021
print("*******Creating a new account*******")
username = input("Enter your username: ")
password = input('Enter your password: ')
print("Account Created")
print("*********LOGIN PAGE *********")
x = input("Enter username: ")
y = input("Enter password: ")
if x == username and y == password:

print("Login Accepted")
else:

print("Login not accepted! Try again ")
print("Thank you !!")

Sample output

*******Creating a new account*******
Enter your username: ISAM-Karthik
Enter your password: isamclass11B2020
Account Created
*********LOGIN PAGE *********
Enter username: ISAM-Karthik
Enter password: isamclass11B2020
Login Accepted !!
Thank you !!

12 | 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

*******Creating a new account*******
Enter your username: ISAM-Class 11B
Enter your password: isamCommerce2020
Account Created
*********LOGIN PAGE *********
Enter username: ISAM-Class 11B
Enter password: isamCommerce
Login not ! Try again
Thank you !!

Program 09

Write a Python program to check whether the number present in the given list by
using break statement.

Program code

# Python program to check numbers in the list by using break statement
# By Suhani, Class XI-B, Academic year 2020-2021
n = int(input('Enter any number: '))
numbers = [11,67,54,68,95,76,45,32,10,20,54,87,84]
for num in numbers:

if num == n:
print ('Number is found in list')
break

else:
print ('Number is not found in list')

Sample output

Enter any number: 45
Number is found in list
Enter any number: 56
Number is not found in list

Program 10
Write a python program to find Simple Interest and get the principal amount, rate
of interest and time from the user.

Program code
# Python program to find SI.
# By Naren Jyothi, Class XI-B, Academic year 2020-2021

13 | 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

p=float(input("Enter the principal amount: "))
r=float(input("Enter the rate of interest: "))
t=float(input("Enter the time period: "))
SI=(p*r*t)/100
print("Simple Interest= ", SI)
Sample output
Enter the principal amount: 3000
Enter the rate of interest: 0.4
Enter the time period: 2
Simple Interest= 24.0

Program 11
Write a Python program to obtain the input from the user and calculate EMI.
Program code
# Python program to calculate EMI
# By Abil Shaju, Class XI-B, Academic year 2020-2021
# for one-month interest
p=float(input("Enter Principle amount:"))
r=float(input("Enter Rate of interest:"))
t=float(input("Enter Time duration:"))
r = r/(12*100)
# for one-month period
t = t*12
EMI = (p*r*pow(1+r,t))/(pow(1+r,t)-1)
print("EMI is :", EMI)
Sample output
Enter Principle amount: 2000
Enter Rate of interest: 7.75
Enter Time duration: 5
EMI is : 40.313919501998576

14 | 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 12

Write a Python program to accept three integers and print the largest of the three
by using if statement.

Program code

# Python program to find the largest of three numbers using if statement.
#By Abil Shaju, Class XI-B, Academic year 2020-2021
a=float (input ("Enter first number:"))
b=float (input ("Enter second number:"))
c=float (input ("Enter third number:"))
if (a > b) and (a > c):

largest=a
elif (b > a) and (b > c):

largest=b
else:

largest =c
print ("The largest number is : ", largest)
Sample output

Enter first number: 1000
Enter second number: 4000
Enter third number: 2000
The largest number is : 4000.0

Program 13

Write a Python program to check whether the given number is odd or even.

Program code

#Python program to check whether the given number is odd or even.
#By Abil Shaju, Class XI-B, Academic year 2020-2021
a=int (input ("Enter a number:"))
if (a % 2) ==0:

print ("The number is even number")
else:

print ("The number is odd number")

15 | 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: 2021
The number is odd number
Enter a number: 2020
The number is even number

Program 14

Write a python program to print three numbers in ascending order by using nested
if concept.

Program code

# python program to print three numbers in ascending order
# By Anandu, Class XI B, Academic year 2020-2021
x = int(input ("Enter first number:"))
y = int(input ("Enter second number:"))
z = int( input ("Enter third number: "))
min=mid=max=0
if x<y and x< y:

if y<z:
min,mid,max = x,y,z

else:
min,mid,max = x,z,y

elif y < x and y<z:
if x<z:
min,mid,max = y,x,z
else:
min,mid,max=y,z,x

else:
if x<y:
min,mid,max = z,x,y
else:
min,mid,max=z,y,x

print("Numbers in ascending order :", min, "," ,mid, ",", max)
Sample output

Enter first number: 500
Enter second number: 100
Enter third number: 300

16 | 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

Numbers in ascending order : 100 , 300 , 500

Program 15

Write a python program to compute the value of Euler’s Number. (Use this formula:
e = 1+1/ 1! + 1/2! +…………1/n!)

Program code

# Python program to find the Euler series:
# By Faris, Class XI-B, Academic year 2020-2021

n= int(input("Enter the number:"))
sum= 1
for i in range (1,n+1):

sum = sum+ (1/i)
print ("The sum of series is", sum)
Sample output
Enter the number:5
The sum of series is 3.2833333333333337

Program 16

Write a program to input any number and to print all-natural numbers up to given
number.

Program code

# python program to print all the natural number
# By Anandu, Class XI B , Academic year 2020-2021
n = int(input("Enter any number:"))
for i in range(1,n+1):

print (i)
Sample output

Enter any number: 5

1
2
3
4
5

17 | 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 17
Write a program to input any number and to find sum of all-natural numbers up
to given number.
Program code
# Python program to print the sum of natural numbers
# By Nuha. Class 11-B, Academic year 2020-2021
n = int(input("Enter any number:"))
sum= 0
for i in range(1,n+1):

sum = sum+i
print ("sum=",sum)
Sample output
Enter any number: 10
sum= 55

Program 18
Write a Python program to display the following pattern:
*
**
***
****
*****
******
Program code
# Python program to print the pattern
# By Sharon, Class 11-B, Academic year 2020-2021
for i in range(1,8):

for j in range(1,i):
print("*", end=' ')

print ( )

18 | 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 19

Write a Python program to display the following pattern:
1
22
333
4444
55555
666666
Program code

# Python program to print the pattern
# By Nuha. Class 11-B, Academic year 2020-2021
n=int(input("Enter number of rows:"))
for i in range(1,n+1):

for j in range(1,i+1):
print(i, end=' ')

print ( )
Sample output

Enter number of rows: 6
1
22
333
4444
55555
666666

Program 20

Write a Python program to display the following pattern:

1
12
123
1234
12345

Program code

# Python program to print the pattern
# By Nuha, Class 11-B, Academic year 2020-2021

19 | 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 number of rows:"))
for i in range(1,n+1):

for j in range(1,i+1):
print(j, end=' ')

print ( )
Sample output

Enter number of rows: 5
1
12
123
1234
12345

Program 21

Write a Python program to input a value in miles and convert it into kilometers (1
kilometer =0.621371 miles)

Program code

# Python program to convert Kilometers into miles
# BY Sumit, Class XI-B Academic year 2020-2021
km = float(input("Enter value in kilometers: "))
onekm = 0.621371
miles = km * onekm
print("The answer is:" , km, '=', miles)
Sample output

Enter value in kilometers: 100
The answer is: 100.0 = 62.137100000000004

Program 22

Write a python program to find the five subject’s average marks.

Program code

# Python program to find average.
# BY Saidev, Class XI-B Academic year 2020-2021
a= float (input ("Enter the first subject number: "))
b =float (input ("Enter the second subject number: "))

20 | 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

c= float (input ("Enter the first subject number: "))
d =float (input ("Enter the second subject number: "))
e= float (input ("Enter the first subject number: "))
average=(a+b+c+d+e)/5
print ("The average of five subjects are:" , average)
Sample output

Enter the first subject number: 34.5
Enter the second subject number: 98.5
Enter the first subject number: 86.8
Enter the second subject number: 89.9
Enter the first subject number: 99.8
The average of five subjects are: 81.9

Program 23

write a python program to print 5, 10,9

Program code

# Python program to find 5, 10,9
# BY SUMIT, Class XI-B Academic year 2020-2021
a=5
print (a)
print (a*2)
print (a*2-1)
Sample output

5
10
9

Program 24

Write a python program to get an input from the user and find the area of the circle.

Program code

# Python program to find the area of the circle
# By- Yahiya Rabbani, Class XI-B, Academic year 2020-2021
PI=3.14
r= float (input ('Enter the radius of a circle:'))

21 | 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

area= PI*r*r
print ("Area of the circle is: " , area)
Sample output

Enter the radius of a circle: 5
Area of the circle is: 78.5

Program 25

Write a python program to get an input from a user and find the area of the triangle
if three sides are given.

Program code

# Python program to find the area of the triangle
# By Mohiitha, Class XI-B, Academic year 2020-2021
a = float (input ('Enter first side: '))
b = float (input ('Enter second side: '))
c = float (input ('Enter third side: '))
s = (a + b + c) / 2
ar= (s*(s-a) *(s-b) *(s-c)) ** 0.5
print (" The area of the triangle is ", ar)
Sample output
Enter first side: 4
Enter second side: 5
Enter third side: 6
The area of the triangle is 9.92

Program 26

Write a python program to get an input from a user and find the perimeter of the
triangle if three sides are given.

Program code

# Python program to print to calculate the perimeter of triangle
# By Shoyab, Class XI-B, Academic year 2020 -2021
a= int(input ("Enter length of first side:"))
b=int(input ("Enter length of second side:"))
c =int(input ("Enter length of third side:"))
perimeter=a+b+c
print("Perimeter of triangle:" , perimeter)

22 | 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 length of first side: 4
Enter length of second side: 5
Enter length of third side: 5
Perimeter of triangle: 14

Program 27

Write a Python program to input any string and count how many vowels in it.
Program code

# Python program to input any string and count vowels
# By Fathima Hida, Class XI-B, Academic year 2020-2021

a=input("Enter any string:")
vowels=['a','e','i','o','u']
count =0
for i in a:

if i in vowels:
count=count+1

print("Total vowels are: ", count)
Sample output

Enter any string: Ambition
Total vowels are: 4

Program 28

Write a Python program to find the given input is palindrome or not.

Program code

# Python program to print palindrome or not
# By Fathima Hida, Class XI-B, Academic year 2020-2021
n = int(input("Enter a number : "))
original = n
reverse = 0
while n != 0:

rem = n % 10
reverse = reverse * 10 + rem

23 | 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 = n // 10
if original == reverse:

print("The number is palindrome")
else:

print("The number is not a palindrome")
Sample output

Enter a number: 32423
The number is palindrome
Enter a number: 12345
The number is not a palindrome

Program 29

Write a Python program to find the factorial of a given number.

Program code

# Python program to print factorial of any number
# By Fathima Hida, Class XI-B, Academic year 2020-2021
n = int(input("Enter any number: "))
sum = 1
for i in range(1, n+1):

sum = sum * i
print ("The factorial of a number", n, "is", sum)
Sample output

Enter any number: 5
The factorial of a number 5 is 120

Program 30

Write a Python program to check if the number is positive or negative and display
an appropriate message

Program code

# Python program to print positive or negative of any number
# By Nyla, Class XI-B, Academic year 2020-2021
num = int(input("Enter a Number: "))
if num>=0:

24 | 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

print(" The number is Positive")
else:

print("The number is Negative")
Sample output

Enter a Number: 400
The number is Positive
Enter a Number: -679
The number is Negative

Program 31

Write a Python program to get any input from the user and check whether the
number is less than 100 or not.

Program code

# Python program to check the number is less than the given number
# By Nyla, Class XI-B, Academic year 2020-2021
A = int (input ("Enter any Number: "))
if A<100:

print ("A is less than 100")
else:

print (“A is not less than 100")
Sample output

Enter any Number: 656
A is not less than 100
Enter any Number: 50
A is less than 100

Program 32

Write a Python script to display the reverse of a number.

Program code

# Python program to print the reverse of a given number
# By Nyla, Class XI-B, Academic year 2020-2021
n = int(input("Enter a number : "))
reverse = 0

25 | 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

while n != 0:
rem = n % 10
reverse = reverse * 10 + rem
n = n // 10

print ("The reverse of the number is : ", reverse)
Sample output

Enter a number: 4567
The reverse of the number is : 7654

Program 33

Write a Python program to check whether the year entered by the user is leap year
or not
Program code

# Python program to print the leap year or not
# By Pavan, Class XI-B, Academic year 2020-2021
year= int(input("Enter a 4-digit year: "))
if year % 100 == 0 :

if year % 400 == 0 :
leap = True

else :
leap = False

elif year %4 == 0 :
leap = True

else :
leap = False

if leap == True :
print(year, "is a leap year")

else :
print(year, "is not a leap year")

Sample output

Enter a 4-digit year: 2020
2020 is a leap year
Enter a 4-digit year: 2021
2021 is not a leap year

26 | 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 34

Write a Python script to print Fibonacci series’ of first 5 elements. Some initial
elements of a Fibonacci series are 0, 1, 1, 2, …

Program code

# Python program to print Fibonacci series
# By Pavan, Class XI-B, Academic year 2020-2021
n = int(input("Enter a number: "))
first=0
second=1
print (first)
print (second)
for a in range (1, n):

third=first + second
print (third)
first, second = second, third
Sample output

Enter a number: 5
0
1
1
2
3
5

Program 35

Write a Python script to print the sum of natural numbers between 1 to 7. Also, print
the sum progressively, i.e., after adding each natural number, print sum so far.

Program code

# Python program to print natural numbers and sum
# By Pavan, Class XI-B, Academic year 2020-2021
sum = 0
for n in range(1, 8) :

sum += n
print ("Sum of natural number ", n, "is", sum)
Sample output

27 | 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

Sum of natural number 1 is 1
Sum of natural number 2 is 3
Sum of natural number 3 is 6
Sum of natural number 4 is 10
Sum of natural number 5 is 15
Sum of natural number 6 is 21
Sum of natural number 7 is 28

Program 36

Write a Python program to print table of 5.

Program code

# Python program to print table 5
# By Pavan, Class XI-B, Academic year 2020-2021
num = 5
for a in range(1, 11) :

print (num, 'x', a, '=', num * a)
Sample output

5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50

Program 37

Write a Python script to print the following patterns.
1
13
135
1357

28 | 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 code

# Python program to print the pattern
# By Pavan, Class XI-B, Academic year 2020-2021
for a in range(3, 10, 2) :

for b in range(1, a, 2) :
print (b, end = ' ')

print ( )

Program 38

Write a Python program to find the sum of squares of the first 100 natural numbers.

Program code

# Python program to print sum of squares
# By Pavan, Class XI-B, Academic year 2020-2021
sqsum = 0
for num in range(1, 101) :

sqsum = sqsum + num
print("Sum of first 100 natural numbers is", sqsum)
Sample output

Sum of first 100 natural numbers is 5050

Program 39

Write a Python program to print as follows:

I
In
Inf
Info
Infor
Inform
Informa
Informat
Informati
Informatic
Informatics

29 | 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 code

# Python program to print pattern
# By Pavan, Class XI-B, Academic year 2020-2021
st =" "
for x in "Informatics" :

st = st + x
print(st)

Program 40

Write a python program to print the numbers from 1-25 except the numbers which
are divided by 3 and 5 using continue statement.
Program code

# Python program to print numbers 1-25, except the numbers divided by 3 and 5
# By Suhani, Class XI-B, Academic year 2020-2021
for i in range (1,25):

if i%3==0 or i%5==0:
continue

print(i)
Sample output

1
2
4
7
8
11
13
14
16
17
19
22
23

30 | 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 41

Write a Python program to check the even numbers in the sequence by using pass
statement.

Program code

# Python program to check the even numbers by using pass statement
# By Mohiitha, Class XI-B, Academic year 2020-2021
n=int(input("Enter any number:"))
print("Even numbers are ")
for i in range (1,n):

if (i%2!=0):
pass

else:
print(i)

Sample output

Enter any number:20
Even numbers are
2
4
6
8
10
12
14
16
18

Program 42

Write a Python program to check the odd numbers in the sequence by using pass
statement.

Program code

# Python program to check the odd numbers by using pass statement
# By Suhani, Class XI-B, Academic year 2020-2021
print("The odd numbers are ")

for i in range(1,21):

31 | 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

if(i%2==0):
continue

else:
print(i)

Sample output

The odd numbers are
1
3
5
7
9
11
13
15
17
19

Program 43

Write a python program to print the multiples of 9 till 100 by using pass statement.

Program code

# Python program to print the multiples of 9 till 100 by using pass statement
# By Suhani, Class XI-B, Academic year 2020-2021
print("These are the multiples of 9")
for i in range(1,101):

if(i%9!=0):
pass

else:
print(i)

Sample output

These are the multiples of 9
9
18
27
36
45

32 | 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

54
63
72
81
90
99

Program 44

Write a Python program to get the input as list from the user, iterate it and display
numbers which are divisible by 5 and if you find number greater than 150 stop the
loop iteration.

Program code

# Python program to print the multiples of 9 till 100 by using pass statement
# By Suhani, Class XI-B, Academic year 2020-2021
lt = [10, 15, 20, 34, 45, 67, 221, 156, 450, 232, 23, 28, 32]
for a in lt:

if (a >=200):
break

if(a % 5 == 0):
print(a)

Sample output

10
15
20
45

Program 45

Write a Python program to display the cube of the number up to a given integer.

Program code

# Python program to display cube
# By Jiya, Class XI-B, Academic year 2020-2021
n=int(input("Enter any number: "))
for n in range(1, n + 1):

33 | 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

print("If the number is ", n, "the cube is", (n * n * n))
Sample output

Enter any number: 5
If the number is 1 the cube is 1
If the number is 2 the cube is 8
If the number is 3 the cube is 27
If the number is 4 the cube is 64
If the number is 5 the cube is 125

Program 46

Write a Python program to get an input from the user and check whether the person
is eligible for voting or not.

Program code

# Python program to check the voting eligibility
# By Daniel, Class XI-B, Academic year 2020-2021
age=int(input("Enter your age:"))
if age>=18:

print("You are eligible for voting")
else:

print("You are not eligible for voting")
print("Thank You !!")
Sample output

Enter your age: 21
You are eligible for voting
Thank You !!
Enter your age: 15
You are not eligible for voting
Thank You !!

Program 47

Write a python program to input any number and check whether the number is a
Prime number or not.
Program code
# Python program to check prime number or not.
# By Dilpreet, Class XI-B, Academic year 2020-2021

34 | 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

val= int ( input ("Enter any number:"))
if val> 1:

for i in range (2, val) :
if (val % i) == 0 :
print ( val, "is not a Prime number ")
print ( i, "times ", val// i, "is" , val)
break

else:
print (val, " is a Prime number")

else:
print (val, "is not a Prime number")

Sample output

Enter any number: 450
450 is not a Prime number
2 times 225 is 450Enter any number: 313
313 is a Prime number

Program 48

Write a Python program to find sum of series if ‘n’ is given, s = 1 + x + x2 + x3 + ….
+ xn .

Program code

# Python program to find the sum of series.
# By Adwaith, Class XI-B, Academic year 2020-2021

x = float(input("Enter value of x:"))
n = int(input("Enter value of n:"))
s=0
for i in range(n+1):

s+=x**i
print("Sum of the series",s)
Sample output

Enter value of x: 5
Enter value of n: 5
Sum of the series 3906.0
Enter value of x: 12.2
Enter value of n: 5

35 | 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

Sum of the series 294402.0499199999

Program 49

Write a Python program to input 3 sides of triangle and print the type of triangle-
Equilateral, Scalene, Isosceles.

Program code

# Python program to find the type of triangle.
# By Gayathri, Class XI-B, Academic year 2020-2021

print("Input lengths of the triangle sides: ")
x = int(input("Enter first side: "))
y = int(input("Enter second side: "))
z = int(input("Enter third side: "))
if x == y == z:

print("It is a equilateral triangle.")
elif x==y or y==z or z==x:

print("It is a isosceles triangle.")
else:

print("It is a scalene triangle.")
Sample output

Input lengths of the triangle sides:
Enter first side: 10
Enter second side: 10
Enter third side: 10
It is a equilateral triangle.

Input lengths of the triangle sides:
Enter first side: 10
Enter second side: 10
Enter third side: 15
It is a isosceles triangle.

Input lengths of the triangle sides:
Enter first side: 10
Enter second side: 15
Enter third side: 20
It is a scalene triangle.

36 | 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 50

Write a Python program to enter numbers as long as user wishes to enter and find
the sum highest and lowest number entered by user.

Program code

# Python program to find the highest and lowest number.
# By Aparna, Class XI-B, Academic year 2020-2021

print("Input some numbers and enter '0' to exit")
count = 0
sum = 0.0
number = 1
while number != 0:

number = int(input(""))
sum = sum + number
count += 1
if count == 0:
print("Input some numbers")
else:
print("Average and Sum of the above numbers are: ", sum / (count-1), 'and', sum)
Sample output

Input some numbers and enter '0' to exit
23
34
5
6
67
7
777
0
Average and Sum of the above numbers are: 131.28571428571428 and 919.0

Program 51

Write a Python program to get input as month from the user and display number
of days in that month.

Program code

# Python program to convert month name to a number of days.

37 | 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

# By Sana, Class XI-B, Academic Year 2020-2021
print("Months: January, February, March, April, May, June, July, August, September,
October, November, December")
month = input("Input any month name: ")
if month == "February":

print("No. of days: 28/29 days")
elif month in ("April", "June", "September", "November"):

print("No. of days: 30 days")
elif month in ("January", "March", "May", "July", "August", "October", "December"):

print("No. of days: 31 days")
else:

print("You have entered incorrect month name")
Sample output
Months: January, February, March, April, May, June, July, August, September, October,
November, December
Input any month name: May
No. of days: 31 days

Months: January, February, March, April, May, June, July, August, September, October,
November, December
Input any month name: February
No. of days: 28/29 days

Program 52
Write a Python program to get 3 sides of a triangle and check if these sides will form
a triangle or not.
Program code
# Python program to check If a triangle can be made with the sides given
# By Karthik V, Class XI-B, Academic year 2020-2021
a = int(input("Enter length of the first side:"))
b = int(input("Enter length of the second side:"))

38 | 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

c = int(input("Enter length of the third side:"))
if (a+b)>c and (b+c)>a and (c+a)>b:

print("A triangle can be formed")
else:

print("A triangle cannot be formed")
Sample output

Enter length of the first side: 10
Enter length of the second side: 15
Enter length of the third side: 20
A triangle can be formed

Enter length of the first side:45
Enter length of the second side:423
Enter length of the third side:23
A triangle cannot be formed

Program 53

Write a Python program to print first N odd numbers in descending order.

Program code

# Python program to print odd numbers till N in descending order
# By Karthik V, Class XI-B, Academic year 2020-2021
a=int(input("Enter any number:"))
print ("First",a,"odd numbers in descending order are:")
for i in range(1,a+1):

print((2*a)-1)
a=a-1

Sample output

Enter any number: 8

First 8 odd numbers in descending order are:
15
13
11
9
7

39 | 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

5
3
1

Program 54

Write a Python program to print the following series:
1 8 15 … 40
-1 -8 -15 … -40

Program code

# Python program to print the series
# By Karthik V, Class XI-B, Academic year 2020-2021
print("1 to 40")
for i in range(1,41,7):

print(i)
print("1 to -40")
for a in range(-1,-41,-7):

print (a)
Sample output

1 to 40
1
8
15
22
29
36

1 to -40
-1
-8
-15
-22
-29
-36

40 | 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 55

Write a Python program to print the number of letters in any name.
Program code

# Python program to print the number of letters in a name
# By Karthik V, Class XI-B, Academic year 2020-2021
a = input("Enter your name: ")
print("Your name is ", len(a)," letters long")
print("Thank You !!!")
Sample output

Enter your name: Karthik
Your name is 7 letters long
Thank You !!!

Program 56

Write a Python program to find the length of a side of a cube when Volume is given
by the user.
Program code

# Python program that finds the volume of a cuboid
# By Karthik V, Class XI-B, Academic year 2020-2021
x = int(input("Enter the volume: "))
Side = x**(1/3)
print("The measure of each side is: ",Side)
Sample output

Enter the volume: 5
The measure of each side is: 1.7099759466766968

Program 57

Write a Python program to find the square root of a number given by the user.
Program code

# Python program that finds the square root of number
# By Karthik V, Class XI-B, Academic year 2020-2021
a = int(input("Enter the number to find the root: "))
b = a**0.5
print("The square root of ",a," is ",b)

41 | 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 the number to find the root: 16
The square root of 16 is 4.0

Program 58
Write a Python program to find the radius of a circle when area is given by the user.
Program code
# Python program that finds ‘R’ of a circle when area is given
# By Mohiitha, Class XI-B, Academic year 2020-2021
a = float(input("Enter the area of the circle:"))
x = a/3.14
y = x**0.5
print("The Radius = ",y)
Sample output
Enter the area of the circle: 360
The Radius = 10.707459153723745

Program 59
Write a Python program that gives both the Area and Circumference of a circle when
R is given by the user.
Program code
# Python program that finds A and C of a circle when R is given.
# By Karthik V, Class XI-B, Academic year 2020-2021
a = float(input("Enter the Radius: "))
Area = 3.14*a*a
C = 2*3.14*a
print("Area of circle = ",Area)
print("Circumference of circle = ", C)
Sample output
Enter the Radius: 10.707
Area of circle = 359.9691258600001
Circumference of circle = 67.23996000000001

42 | 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 60

Write a Python program to find speed when distance and time is given by the user.
Program code

# Python program that find speed
# By Karthik V, Class XI-B, Academic year 2020-2021
x = int(input("Enter Distance in Meters: "))
y = int(input("Enter time in seconds: "))
z = x/y
print("The speed = ",z)
Sample output

Enter Distance in Meters: 234
Enter time in seconds: 64
The speed = 3.65625

Program 61

Write a Python program to find the area of a parallelogram.
Program code

# Python program that find Area of a parallelogram
# By Karthik V, Class XI-B, Academic year 2020-2021
l = int(input("Enter the Length: "))
b = int(input("Enter the Base: "))
area = l*b
print("The area = ",area)
Sample output

Enter the Length: 10
Enter the Base: 5
The area = 50

Program 62

Write a Python program to find the divisibility of a number with another number.

Program code

# Python program that find the divisibility of a number with another number.
# By Sharon, Class XI-B, Academic year 2020-2021

43 | 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

a = float(input("Enter the first number: "))
b = float(input("Enter the second number: "))
if a%b==0:

print("The number is divisible")
else:

print("The number is not divisible")
Sample output

Enter the first number: 286
Enter the second number: 12
The number is not divisible

Enter the first number: 3435
Enter the second number: 5
The number is divisible

Program 63

Write a Python program which perform arithmetic operations.
Program code

# Python calculator
# By Karthik V, Class XI-B, Academic year 2020-2021
a = int(input("Enter First Number: "))
b = int(input("Enter Second Number: "))
print("Enter which operation would you like to perform?")
op= input("Enter any of these operator for specific operation +,-,*, /, %, //: ")
result = 0
if op == '+':

result = a + b
elif op == '-':

result = a - b
elif op == '*':

result = a * b
elif op == '/':

result = a / b
elif op == '%':

result = a % b
elif op == '//':

44 | 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

result = a // b
else:

print("Input operator is not recognized!")
print(a, op , b, ":", result)
Sample output
Enter First Number: 23
Enter Second Number: 56
Enter which operation would you like to perform?
Enter any of these operator for specific operation +,-,*, /, %, //: +
23 + 56 : 79

Enter First Number: 34
Enter Second Number: 21
Enter which operation would you like to perform?
Enter any of these operator for specific operation +,-,*, /, %, //: ==
Input operator is not recognized!

Program 64
Write a Python program to find the distance when Speed and Time is given by the
user.
Program code
# Python program that find distance:
# By Karthik V, Class XI-B, Academic year 2020-2021
x = int(input("Enter Speed in m/s: "))
y = int(input("Enter time in seconds: "))
z = x*y
print("The Distance covered = ",z,"m")
Sample output
Enter Speed in m/s: 33
Enter time in seconds: 4
The Distance covered = 132 m

45 | 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 65

Write a Python program to find the volume of a sphere.
Program code

# Python program that find the volume of a sphere
# By Karthik V, Class XI-B, Academic year 2020-2021
a = int(input("Enter the radius: "))
volume = 4/3*3.14*a**3
print("The volume is: ", volume)
Sample output

Enter the radius: 7
The volume is: 1436.0266666666666

Program 66

Write a Python program to find death rate in a country if the total death cases are
provided by the user.
Program code

# Python program to find the death rate
# By Karthik V, Class XI-B, Academic year 2020-2021
a = int(input("Enter the amount of people dead: "))
x = a/1000
print("The death rate is: ",x)
Sample output

Enter the amount of people dead: 3400
The death rate is: 3.4

Program 67

Write a Python program to create voting result finder.
Program code

# Python program for voting result finder
# By Karthik V, Class XI-B, Academic year 2020-2021
a = int(input("Enter the votes for party A: "))
b = int(input("Enter the votes for party B: "))
if a > b:

print( "Party A has won the election, Congrats!!!")

46 | 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 a < b:
print("Party B has won the election, Congrats!!!")

else:
print("It’s a draw")

Sample output

Enter the votes for party A: 30000
Enter the votes for party B: 28000
Party A has won the election, Congrats!!!

Enter the votes for party A: 40000
Enter the votes for party B: 40000
It’s a draw

Program 68

Write a Python program to find new savings after deducting the interest from the
user account.
Program code

# Python program to find the bank account balance
# By Abai Babu V, Class XI-B, Academic year 2020-2021
savings = int(input("Enter the amount in your account: "))
interest = int(input("Enter Interest: "))
a = savings - interest
print('The New amount is: ', a)
Sample output

Enter the amount in your account: 56000
Enter Interest: 560
The New amount is: 55440

Program 69

Write a Python program to find the perimeter of a cuboid.

Program code

# Python program to find the perimeter of a cuboid
# By Karthik, Class XI-B, Academic year 2020-2021
l = int(input("Enter Length: "))

47 | 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 = int(input("Enter Breadth: "))
h = int(input("Enter Height: "))
perimeter_of_cuboid= 2*((l*b)+(b*h)+(h*l))
print("The Perimeter of a cuboid is: ", perimeter_of_cuboid)
Sample output

Enter Length: 34
Enter Breadth: 3
Enter Height: 5
The Perimeter of a cuboid is: 574

Program 70

Write a Python Program to find lowest and second lowest number in a list.

Program code

# Python program to find the smallest element in the list
# By Arthana, Class XI-B, Academic year 2020-2021
list1 = [10, 20, 4, 45, -54, 344, -21, 0, 99]
list1.sort()
print("Smallest element is:", list1[:1])
Sample output

Smallest element is: [-54]

Program 71

A store charges Rs.120 per item if you buy less than 10 items. If you buy between
10 and 99 items, the cost is Rs.100 per item. If you buy 100 or more items, the cost
is Rs.70 per item. Write a program that asks the user how many items they are
buying and prints the total cost.

Program code

# Python program to find the smallest element in the list
# By Binshad, Class XI-B, Academic year 2020-2021
item = int(input("Enter the total number of item = "))
if item < 10 :

print("Total cost = ",item * 120 , "rs")
elif 10 < item and item < 99 :

print("Total cost = ",item * 100, "rs")

48 | 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

else :
print("Total cost =",item*70, "rs")

Sample output

Enter the total number of item = 45
Total cost = 4500 rs

Program 72

Write a Python script that asks the user to enter a length in centimeters. If the user
enters a negative length, the program should tell the user that the entry is invalid.
Otherwise, the program should convert the length to inches and output the result.
There are 2.54 centimeters in an inch.
Program code

# Python program to calculate the cm into inches
# By Binshad, Class XI-B, Academic year 2020-2021
cm = int(input("Enter length in cm : "))
if cm < 0:

print("Invalid entry")
else:

print(cm/2.54, "Inches")
Sample output

Enter length in cm : 345
135.82677165354332 Inches

Program 73

Write a program to determine the probability of drawing an ace with the help of
Python code.

Program code

# Python program to find the probability.
# By Binshad, Class XI-B, Academic year 2020-2021
cards = int(input("Enter the total cards:"))
aces = int(input("Enter the total aces:"))
ace_probability = aces / cards
print(round(ace_probability, 2))

49 | 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 the total cards: 52
Enter the total aces: 4
0.08

Program 74

Write a Python program to count the Consonants or Vowels of the given string.

Program code

# Python program to find the vowels and consonants
# By Binshad, Class XI-B, Academic year 2020-2021
str=input("Please enter a string as you wish: ");
vowels=0
consonants=0
for i in str:

if(i == 'a'or i == 'e'or i == 'i'or i == 'o'or i == 'u' or
i == 'A'or i == 'E'or i == 'I'or i == 'O'or i == 'U' ):

vowels=vowels+1
else:

consonants=consonants+1
print("The number of vowels:”, vowels)
print("\nThe number of consonants:”, consonants)
Sample output

Please enter a string as you wish: InformaticsPractices
The number of vowels: 7
The number of consonants: 13

Program 75

Write a python to print all prime in a given interval.

Program code

# Python program to find the prime numbers within the given interval
# By Binshad, Class XI-B, Academic year 2020-2021
lower = int(input("Enter lower range: "))
upper = int(input("Enter upper range: "))
for num in range(lower,upper + 1):

50 | 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


Click to View FlipBook Version