0% found this document useful (0 votes)
98 views21 pages

Class11 Programs Manual

The document contains 17 Python programs that demonstrate various programming concepts like finding the largest/smallest number in a list, generating patterns, checking if a number is prime, generating the Fibonacci series, calculating GCD and LCM of numbers, counting vowels/consonants in a string, searching an element in a list, and more. The programs take user input, perform various operations on lists, tuples, dictionaries and display the output.

Uploaded by

wosolir748
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)
98 views21 pages

Class11 Programs Manual

The document contains 17 Python programs that demonstrate various programming concepts like finding the largest/smallest number in a list, generating patterns, checking if a number is prime, generating the Fibonacci series, calculating GCD and LCM of numbers, counting vowels/consonants in a string, searching an element in a list, and more. The programs take user input, perform various operations on lists, tuples, dictionaries and display the output.

Uploaded by

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

Program1 : Find the largest and smallest number in the list.

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+………..

x=float(input("enter the value of x:"))


n=int(input("enter the value of n:"))
s=0
for a in range (n+1):
s += x**a
print ("sum of first", n,"terms",s )

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.

str= input ("Enter the string")


rev= str[ : : -1]
if (str==rev):
print ("string is palindrome")
else:
print ("string is not palindrome")

output
Enter the string123
string is not palindrome

Enter the string121


string is 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

Program7: write a program to check whether given number is prime or not.

num=int(input("enter the number:"))


for i in range(2,num):
ifnum % i == 0:
print(num,"is not a prime number")
break
else:
print(num,"is a prime number")

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

n=int(input("enter the value of n:"))


a=0
b=1
sum=0
count=1
print("fibonacciseries:",end=" ")
while(count<=n):
print(sum,end=" ")
count +=1
a=b
b=sum
sum=a+b

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.

x = int(input("Enter the 1st number: "))


y = int(input("Enter the 2nd number: "))
if x> y:
smaller = y
else:
smaller = x
for i in range(1,smaller+1):
if((x%i==0)and(y%i==0)):
hcf = i
lcm = (x*y)/hcf
print("The hcf of x and y is ",hcf)
print("The hcf of x and y is ",lcm)

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.

L=input("enter the sentence:")


lowercase=0
uppercase=0
digits=0
alphabets=0
for a in L:
if a.islower():
lowercase+=1
elif a.isupper():
uppercase+=1
elif a.isdigit():
digits+=1
elif a.isalpha():
alphabets+=1
print("number of uppercase letter is:",uppercase)
print("number of lowercase letter is:",lowercase)
print("number of digits letter is:",digits)
print("number of alphabets are:",alphabets)

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.

val=eval(input("Enter a list "))


print("Original List is:",val)
s=len(val)
if s%2!=0:
s=s-1
for i in range(0,s,2):
val[i],val[i+1]=val[i+1],val[i]
print("List after swapping :",val)

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

enter the number to be searched:95


item found at the position: 3

enter the number to be searched:999


item found at the position: 4

enter the number to be searched:4


item not found

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.

n=int(input("enter the no of students:"))


result={}
for i in range(n):
print("enter details of students :",i+1)
rollno=int (input("Rollno"))
name=input("Name")
marks=int(input("marks"))
result[rollno]=[name,marks]
print(result)
for student in result:
if result[student][1]>75:
print(result[student][0])

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

Program17 : Write a Python program to count the frequency of numbers.

list1=eval(input("Enter a list of numbers:"))


length=len (list1)
count=0 # estimating the count of the number be 0
for i in range(0, length) : # finding frequency of the given element
num=int (input (" enter the number for which frequency is required:"))
if num==list1[i]
count=+1
print( "frequency of the given number is:"count)

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.

a = [] number = int(input( "Please Enter the Total Elements : "))


for i in range(number):
value = int(input("Please enter the %d Item : " %i))
a. append(value)
for i in range(number -1):
for j in range(number - i - 1):
if(a[j] > a[j + 1]):
temp = a[j]
a[j] = a[j + 1]
a[j + 1] = temp
print("The Result in Ascending Order : ", a)

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

You might also like