Practicl_file_Computer[1]
Practicl_file_Computer[1]
COMPUTER SCIENCE
CLASS XI
Code:083
PRACTICAL FILE
(SESSION 2024-25)
limit.
12
123
13. WAP to remove all odd numbers from the given list
18. WAP in Python to find and display the sum of all the values
19. WAP to shift the negative number to left and the positive
numbers to right.
26. Q31Program 25:WAP a menu-driven program to enter your friends’ name and
their phone numbers and store them in the dictionary as key-value pair. Per-
form following operations on dictionary:
(a) Display the name and phone number of all your friends.
(b) Add a new key-value pair in this dictionary and display the modified dic-
tionary.
27. WAP to convert number entered by the user into its corre-
sponding number in words.
x=int(input("Enter a number"))
y=int(input("enter a power"))
z=x**y
print(z)
#Output
Enter a number5
enter a power4
625
#Output
#Output
enter no:7
Odd number
#Output
#Output
Enter the limit23
fibonacci series
1 2 3 5 8 13 21
6.Write a program to display prime numbers up to a
certain limit.
x=int(input("Enter limit"))
for num in range(x+1):
i=2
while i<num:
if num%i==0:
break
i+=1
else:
print("Num is a prime number")
#Output
Enter limit55
Num is a prime number
Num is a prime number
Ayan Computer Science
Num is a prime number
Num is a prime number
Num is a prime number
Num is a prime number
Num is a prime number
Num is a prime number
Num is a prime number
Num is a prime number
Num is a prime number
Num is a prime number
Num is a prime number
Num is a prime number
Num is a prime number
Num is a prime number
Num is a prime number
Num is a prime number
#Output
i=1
s=0
num=int(input("Enter a Number"))
while i<=num:
if num%i==0:
s+=i
i=i+1
if s==num:
Ayan Computer Science
print("Its a perfect number")
else:
print("its not a perfect
number")
#Output
Enter a Number5
its not a perfect number
9.Write a program to print the
following pattern:
#1
#1 2
#1 2 3
i=1
while i<=3:
j=1
while j<=i:
print(j,end=" ")
j=j+1
#Output
1
1 2
1 2 3
10.Write a program to accept a string
and display whether it is a
palindrome.
str=input("Enter a string")
l=len(str)
p=l-1
index=0
while (index<p):
if (str[index]==str[p]):
index+=1
p-=1
else:
print("Not a palindrome")
break
Ayan Computer Science
else:
print("Number is Palindrome")
#Output
Enter a string4
Number is Palindrome
str1=input("Enter a string")
n=d=c=s=u=l=o=0
for ch in str1:
if ch.isalpha():
n+=1
if ch.isupper():
u+=u
elif ch.islower():
l+=l
elif ch.isalpha():
c+=1
if ch.isdigit():
d+=1
if ch.isspace():
s+=1
else:
o+=1
print ("No. of alphabets and digits",n)
print ("No. of upper case letters",u)
print ("No. of lower case letters",l)
print ("No. of spaces",s)
print ("No. of digits",d)
print ("No. of special characters",o)
str1=input("Enter a string")
print("original string:",str1)
str2=""
x=str1.split()
for a in x:
str2+=a.capitalize()+" "
print(str2)
def main():
L=[2,7,12,5,10,15,23]
for i in L:
if i%2==0:
L.remove(i)
print(L)
main()
#Output
L=[41,6,9,13,4,23]
m=max(L)
secmax=L[0]
for i in range(1,len(L)):
if L[i]>secmax and L[i]<m:
secmax=L[i]
print(secmax)
#Output
41
list=[1,3,5,7,8]
finallist=[list[0]]
for i in range(1,len(list)):
finallist+=[finallist[i-
1]+list[i]]
print(finallist)
#Output
L=[3,21,5,6,3,8,21,6]
L1=[]
L2=[]
for i in L:
if i not in L2:
x=L.count(i)
L1.append(x)
L2.append(i)
print("Element","\t\t\t","Frequency")
for i in range(len(L1)):
print(L2[i],"\t\t\t",L1[i])
#Output
Element Frequency
3 2
21 2
5 1
6 2
8 1
L=['AUSHIM','LEENA','AKHTAR','HIBA','NISHANT','AM
AR']
count=0
for i in L:
if i[0] in ('aA'):
count+=1
print(i)
print("Appearing",count,"Times")
#Output
AUSHIM
AKHTAR
AMAR
Appearing 3 Times
L=[33,13,92,99,3,12]
sum=0
x=len(L)
for i in range(0,x):
if type(L[i])==int:
if L[i]%10==3:
sum+=L[i]
print(sum)
#Output
49
#Output
classxi=dict()
n=int(input("Enter the number of sections"))
#Output
Output
Output
Enter the number of countries5
Enter the name of the country: Australia
Enter the capital of the country: Vienna
Ayan Computer Science
Enter the currency of the country: Euro
Enter the name of the country: China
Enter the capital of the country: Beijing
Enter the currency of the country: Yuan
Enter the name of the country: India
Enter the capital of the country: Delhi
Enter the currency of the country: Rupees
Enter the name of the country: France
Enter the capital of the country: Paris
Enter the currency of the country: Euro
Enter the name of the country: United Kingdom
Enter the capital of the country: London
Enter the currency of the country: Pound
Q.WAP a menu-driven program to enter your friends’ name and their phone numbers and store them in
the dictionary as key-value pair. Perform following operations on dictionary:
(a) Display the name and phone number of all your friends.
(b) Add a new key-value pair in this dictionary and display the modified dictionary.
n=int(input("No. of friends:"))
dict={}
for i in range(n):
name=input("Name:")
ph_no=int(input("Phone no.:"))
dict[name]=ph_no
while True:
print("MENU\n\
1.Display name & Phone number\n\
2.Add a new name\n\
3.Delete a name\n\
4.Modify an existing number\n\
5.Check if a name is there\n\
6.Display dictionary in sorted order\n\
7.Exit")
ch=int(input("Enter your choice(1-6):"))
if ch==1:
for i in dict:
print(i,"-",dict[i])
elif ch==2:
name1=input("Enter name:")
ph_no1=int(input("Enter phone number:"))
dict[name1]=ph_no1
print("Modified dictionary:", dict)
elif ch==3:
name1=input("Name of friend to be deleted:")
dict.pop(name1)
print("Modified dictionary:", dict)
elif ch==4:
name1=input("Name of friend:")
ph_no1=int(input("New phone number:"))
dict[name1]=ph_no1
elif ch==5:
name1=input("Name of friend:")
if name1 in dict:
print("Friend is in dicionary")
else:
print("Friend is not in dictonary")
elif ch==6:
D=dict
dict1=sorted(D.items())
print("Modified dictionary", dict1)
elif ch==7:
break
else:
print("Invalid choice")
MENU
1.Display name & Phone number
2.Add a new name
3.Delete a name
4.Modify an existing number
5.Check if a name is there
6.Display dictionary in sorted order
7.Exit
Ayush – 9870
Rohit - 8679
Anil - 6543
Hari - 3240
MENU
1.Display name & Phone number
2.Add a new name
3.Delete a name
4.Modify an existing number
5.Check if a name is there
6.Display dictionary in sorted order
7.Exit
MENU
1.Display name & Phone number
2.Add a new name
3.Delete a name
4.Modify an existing number
5.Check if a name is there
6.Display dictionary in sorted order
7.Exit
Ayush - 9870
Rohit - 8679
Anil - 7658
Hari - 3240
MENU
1.Display name & Phone number
2.Add a new name
3.Delete a name
4.Modify an existing number
5.Check if a name is there
6.Display dictionary in sorted order
7.Exit
Enter your choice(1-6):7
Output