Class11 Programs Manual
Class11 Programs Manual
Class11 Programs Manual
list =[ ]
num = int(input("how many no"))
for n in range(num):
number=int(input("enter the number"))
list.append(number)
print("maximum element in the list is", max(list))
print("minimum element in the list is ", min(list))
output
how many no 4
enter the number12
enter the number68
enter the number35
enter the number9
maximum element in the list is 68
minimum element in the list is 9
1
Program2 : Find the third largest number in the list.
a=[]
n=int(input("enter number of elements:"))
for n in range(1,n+1):
b=int(input("enter the element: "))
a.append(b)
a.sort()
print("the third largest number is:",a[n-3])
output
enter number of elements:4
enter the element: 78
enter the element: 56
enter the element: 45
enter the element: 89
the third largest number is: 56
2
Program3a : Write a program to print the following pattern.
12345
1234
123
12
1
for i in range(5,0,-1):
for j in range(1,i+1):
print(j,end=' ')
print()
output
12345
1234
123
12
1
3
Program 3b : Write a program to print the following pattern.
*
**
***
****
*****
for i in range(1,6):
for j in range(1,i+1):
print('*',end=' ')
print()
output
*
**
***
****
*****
4
Program4 : Write a program to input the values of X and n and print the sum of
the following series.S= 1+x+x2+x3+………..
output
enter the value of x:2
enter the value of n:4
sum of first 4 terms 31.0
5
Program5 : Write program to input a string and determine whether it is a
palindrome or not.
output
Enter the string123
string is not palindrome
6
Program6 : Write a program to determine whether a number is a PERFECT
NUMBER, ARMSTRONG NUMBER, PALINDROME NUMBER.
num=int(input("Enter a number"))
sum=0
for i in range (1,num):
ifnum%i==0:
sum=sum+i
if sum== num:
print (num, " is a perfect number")
else:
sum=0
temp=num
rem=0
while temp>0:
rem=temp%10
sum= sum+(rem*rem*rem)
temp=temp//10
if sum==num:
print (num, "is Armstrong number")
else:
temp=num
rev=0
digit=0
while temp>0:
digit=temp%10
rev=rev*10+digit
temp=temp//10
if rev ==num:
print (num, " is palindrome")
else:
print (num, "does not belongs to any of the three numbers
PERFECT, ARMSTRONG, PALINDROME")
output
Enter a number6
6 is a perfect number
Enter a number153
7
153 is Armstrong number
Enter a number121
121 is palindrome
output
enter the number:5
5 is a prime number
enter the number:22
22 is not a prime number
8
program8 : write a program to generate Fibonacci series
output
enter the value of n:5
fibonacci series: 0 1 1 2 3
enter the value of n:7
fibonacci series: 0 1 1 2 3 5 8
9
Program9 : write a program to compute the GCD and LCM of two integers.
output
Enter the 1st number: 45
Enter the 2nd number: 56
The hcf of x and y is 1
The hcf of x and y is 2520.0
10
program10 : write a program to count and display the number of vowels,
consonants, uppercase and lowercase characters.
output
enter the sentence: PyThon123
number of uppercase letter is: 2
number of lowercase letter is: 4
number of digits letter is: 3
number of alphabets are: 6
11
Program11 : write a program to write largest and smallest number in tuple.
tuple=(78,67,44,9,34,88,11,122,23,19)
print("tuple items are=",tuple)
print("largest item in tuple=",max(tuple))
print("smallest item in tuple=",min(tuple))
output
tuple items are= (78, 67, 44, 9, 34, 88, 11, 122, 23, 19)
largest item in tuple= 122
smallest item in tuple= 9
12
Program12 : Write a python program to input a list of numbers and swap
positions of elements of even location with elements of odd location.
output
Enter a list 3,4,5,6
Original List is: 3,4,5,6
List after swapping: 4, 3, 6, 5
13
program13 : write a python program to input a list of elements and search for
the given element in the list.
l=[2,58,95,999,65,32,15,1,7,45]
n=int(input("enter the number to be searched:"))
found=0
for x in l:
if x==n:
print("item found at the position:",l.index(n)+1)
found=1
else:
if found == 0:
print("item not found")
output
enter the number to be searched:2
item found at the position: 1
14
Program14 : write a program to input a list number and find the smallest and
largest number from the list.
numlist=[]
number=int(input("enter the total number of elements:"))
for i in range(1,number+1):
value=int(input("enter the elements"))
numlist.append(value)
print("the smallest element in the list is:",min(numlist))
print("the largest element in the list is:",max(numlist))
output
enter the total number of elements:5
enter the elements23
enter the elements45
enter the elements10
enter the elements78
enter the elements34
the smallest element in the list is: 10
the largest element in the list is: 78
15
Program15 : write a dictionary with the roll no, name, marks and students in a
class and display the name of the students who have marks above 75.
output
enter the no of students:3
enter details of students : 1
Rollno1
Name a
marks55
enter details of students : 2
Rollno2
Name b
marks60
enter details of students : 3
Rollno3
Name c
marks65
{1: ['a', 55], 2: ['b', 60], 3: ['c', 65]}
16
Program16 : Write a Python program to create a dictionary at competition
winners with their names and number of wins and check a value in the
dictionary.
d={}
n=int(input('Enter number of the winners :'))
for i in range (n):
a=input('Enter name of the winner:')
b=int(input('Enter the number of wins of the winner:'))
d[a]=b
print('\n')
print('name of the winners','\t','number of wins')
for i in d:
print(i,'\t','\t','\t',d[i])
print('\n')
val=int(input('Enter the value to be checked:'))
for i in (d.values()):
if val==i:
print('found')
break
else:
print('not found')
OUTPUT
Enter number of the winners : 3
Enter name of the winner: Manav1
Enter the number of wins of the winner: 12
Enter name of the winner: Manav2
Enter the number of wins of the winner: 13
Enter name of the winner: Manav3
Enter the number of wins of the winner: 14
name of the winners number of wins
Manav1 12
Manav2 13
17
Manav3 14
Enter the value to be checked: 14
found
output
Enter a list of numbers: 2, 58, 95, 999, 2, 65, 32, 1, 7, 2, 45
Enter the number for which frequency is required: 2
Frequency of the given number is: 3
18
Program18 : Write a Python program to calculate and print the quadratic
equations.
import cmath
a = float(input('Enter a: '))
b = float(input('Enter b: '))
c = float(input('Enter c: '))
# calculate the discriminant
d = (b**2) - (4*a*c)
# find two solutions
sol1 = (-b-cmath.sqrt(d))/(2*a)
sol2 = (-b+cmath.sqrt(d))/(2*a)
print('The solution are {0} and {1}'.format(sol1,sol2))
Output
Enter a: 8
Enter b: 5
Enter c: 9
The solution are (-0.3125-1.0135796712641785j) #and (-
0.3125+1.0135796712641785j)
19
Program19 : Write a Python program to sort a list elements.
Output
Please Enter the Total Elements : 4
Please enter the 0 Item : 10
Please enter the 1 Item : -4
Please enter the 2 Item : 10
Please enter the 3 Item : 5
The Result in Ascending Order : [-4, 5, 10, 10]
20
Program20 : Write a Python program to find the factorial of a number.
num = int(input("Enter a number: "))
factorial = 1
if num < 0:
print(" Factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)
Output
Enter a number: 10
The factorial of 10 is 3628800
21