0% found this document useful (0 votes)
25 views11 pages

Class XI-programs (Annual Practical) - 1

Uploaded by

robloxianmad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views11 pages

Class XI-programs (Annual Practical) - 1

Uploaded by

robloxianmad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

PROGRAM : 5

SUM OF DIGITS

QUES: Write a program to find the sum of digits of an input number.

AIM: To write a python program to find the sum of digits of an input number.

CODE:

n=int(input("Enter a number:"))
sum=0
org=n
while n>0:
r=n%10
sum+=r
n=n//10
print("The sum of digits of",org,"is",sum)
PROGRAM : 6
FIBONACCI SERIES

QUES: Write a program to input a value n and find Fibonacci series of n terms.

AIM: To write a python program to input a value n and find Fibonacci series of n
terms.

CODE:

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


a=0
b=1
print("Fibonacci series are")
print(a)
print(b)
for i in range(3, n+1):
c=a+b
print(c)
a=b
b=c
PROGRAM : 8

PALINDROME NUMBER

QUES: Write a program to input a number n and find if it is Palindrome or not.

AIM: To write a python program to input a number n and find if it is Palindrome or


not.

CODE:

n=int(input('enter a number'))
org=n
rev=0
while n!=0:
r=n%10
rev=rev*10+r
n=n//10
if org==rev:
print(org,"is an Palindrome number")
else:
print(org,"is not an Palindrome number")
PROGRAM : 11
GENERATE PATTERNS

QUES: Write a program to generate the following patterns using nested loops:

a) * b) 12345 c) A
** 1234 AB

*** 123 ABC


**** 12 ABCD
***** 1 ABCDE

AIM: To write a python program to generate the given patterns.

CODE:

a) for i in range(5):
for j in range(i):
print('*',end='')
print()

b)
for i in range(5):
for j in range(5-i):
print(j+1,end='')
print()
c)
for i in range(1,6):
for j in range(i):
print(chr(65+j),end='')
print()
PROGRAM : 13

STRING – NUMBER OF VOWELS, CONSONANTS, UPPERCASE,


LOWERCASE

QUES: Write a program to accept a string and print number of vowels, consonants,
uppercase and lowercase.

AIM: To write a python program to accept a string and print number of vowels,
consonants, uppercase and lowercase.

CODE:

str=input('Enter a string:')
v,c,l,u=0,0,0,0
for i in str:
if i.isalpha():
if i in 'aeiouAEIOU':
v+=1
else:
c+=1
if i.islower():
l+=1
else:
u+=1
print('Number of vowels is',v)
print('Number of consonants is',c)
print('Number of lowercase is',l)
print('Number of uppercase is',u)
PROGRAM : 15

NUMBER OF EVEN AND ODD NUMBERS

QUES: Write a program to input a list and count the number of even and odd
numbers in the list.

AIM: To write a python program to input a list and count the number of even and odd
numbers in the list.

CODE:

m=[]
print('Enter any 10 numbers:')
for i in range(10):
n=int(input())
m.append(n)
even=odd=0
for i in m:
if i%2==0:
even+=1
else:
odd+=1
print("The number of even nos in the list is",even)
print("The number of odd nos in the list is",odd)
PROGRAM : 16

SEARCH - LIST

QUES: Write a program to search an input number in a list and return its index.

AIM: To write a python program to search an input number in a list and return its
index..

CODE:

m=[]
print('Enter any 10 numbers:')
for i in range(10):
n=int(input())
m.append(n)
s=int(input("Enter a number to be searched in the list:"))
flag=0
for i in range(len(m)):
if m[i]==s:
flag=1
print(s,"is in the index",i,"of list",m)
if flag==0:
print(s,"is not found in",m)
PROGRAM : 17
LIST OPERATIONS

QUES: Write a Python program to create a menu driven program to perform various
list operations:
● Append an element
● Insert an element in a desired position
● Modify an existing element
● Delete an existing element
● Search an element and display its index
● Sort the list
● Display the list.
AIM:
To create a menu driven program to perform the given action.

CODE:
l=[]
print("Enter any 10 numbers:")
for i in range(0,10):
n=int(input())
l.append(n)
while True:
print(" MENU ")
print(" 1. Append an element")
print(" 2. Insert an element in desired position")
print(" 3. Modify the existing element")
print(" 4. Delete an element")
print(" 5. Search an element")
print(" 6. Sort the list")
print(" 7. Display the list")
print(" 8. Exit")
ch=int(input("Enter your choice to do list operations:"))
if (ch==1):
n=int(input("Enter a number to append:"))
l.append(n)
print("Now list is ",l)
elif(ch==2):
n=int(input("Enter a number to be inserted:"))
p=int(input("Enter the position where number to be inserted:"))
l.insert(p-1,n)
print("Now list is ",l)
elif(ch==3):
n=int(input("Enter a number to be modified:"))
p=int(input("Enter the position where number to be modified:"))
l[p-1]=n
print("Now list is ",l)
elif(ch==4):
n= int(input("Enter the number to be deleted"))
if (n in l):
l.remove(n)
else:
print(n," is not an element of list")
print("Now list is ",l)
elif(ch==5):
n=int(input("enter a number to be searched"))
if (n in l):
print(" Position of the number is ",l.index(n)+1)
else:
print("not available")
print("Now list is ",l)
elif(ch==6):
c=input("Enter A for sort ascending or D for sort descending")
if (c=='A'):
l.sort()
else:
l.sort(reverse=True)
print("Now list is ",l)
elif(ch==7):
print("List is ",l)
elif(ch==8):
break
else:
print("invalid entry. Try again....")
PROGRAM : 19

DICTIONARY - STUDENT

QUES: Write a Python program to create a dictionary of 5 students with rollno as key
and marks as value. Now write a menu driven program to:
● Add new students details.
● Modify student marks
● Delete a student who has taken TC
● Exit

AIM:
To create a dictionary of 5 students with rollno as key and marks as value and write a menu
driven program as given.

CODE:
s={}
for i in range(5):
r,m=eval(input('Enter rollno and marks of existing student:'))
s[r]=m
print('The details of existing student is ',s)
while True:
print('Menu \n 1. ADD NEW STUDENT \n 2. MODIFY MARKS \n 3.
DELETE STUDENT \n 4. EXIT')
choice=int(input('Enter your choice'))
if choice==1:
r,m=eval(input('Enter rollno and marks of a new student:'))
s[r]=m
print('The details of students after entering new student details are:',s)
elif choice==2:
r,m=eval(input('Enter rollno and marks of a student which has to be
updated:'))
s[r]=m
print('The details of students after modifying are',s)
elif choice==3:
r=eval(input('Enter rollno of a student who has taken TC:'))
del s[r]
print('The details of students after deleting a student are:',s)
elif choice==4:
print('work completed....')
break
else:
print('Invalid choice')
PROGRAM: 20
DICTIONARY - EMPLOYEE

QUES: Write a Python program to create a dictionary of 5 employees with eno as key
and salary as value. Now display the number of employees whose salary is greater
than 50000.

AIM:
To create a dictionary of 5 employees with eno as key and salary as value. Also to
display the number of employees whose salary is greater than 50000.

CODE:

e={}
for i in range(5):
n,s=eval(input('Enter employee number and salary:'))
e[n]=s
print('The details of existing student is ',e)
count=0
for i in e:
if e[i]>50000:
count+=1
print('The number of employee who get more than 50000 as salary are', count)

You might also like