Class Xi Cs Practical File 2022-23
Class Xi Cs Practical File 2022-23
COMPUTER SCIENCE
PRACTICAL FILE
INDEX
1
1 2
1 23
1 234
1 2345
Sr.No. List of Program Pageno. Date Signature
OUTPUT :
OUTPUT:
enter any number12321
12321 is a palindrome number
enter any number123
123 is not a palindrome number
Program-4 : Write a program to accept a number from the user and display whether it is a
prime number or not.
OUTPUT :
enter any number12
12 is not prime number
1
12
123
1234
12345
for i in range(1,6):
for j in range(1,i+1):
print(j,end=" ")
print()
OUTPUT :
1
12
123
1234
12345
Program – 6 Write a program to display the following pattern :
1
23
456
7 8 9 10
11 12 13 14 15
k=1
for i in range(0,6):
for j in range(1,i+1):
print(k,end=" ")
k=k+1
print()
OUTPUT :
1
23
456
7 8 9 10
11 12 13 14 15
Program 7: Write a program that reads a string and print its statistics like :
Number of Uppercase letters, Number of lowercase letters, Number of alphabets,
Number of digits, Number of symbols.
OUTPUT :
enter any string: This is a Sample String 123
No. of alphabets 19
No. of uppercase letters 3
No. of lowercase letters 16
No. of digits 3
No. of symbols 5
Program-8 : Write a program that asks the user for a string s and character c and then it
prints the location of the character c in the string s.
flag=0
for i in range(0,len(s)):
if s[i]==c:
print("in ",s,"character",c,"occured at location ",i+1)
flag=1
if flag==0:
print(c,"does not occur in ",s)
OUTPUT :
Enter any string: pisgurukul
Enter any character u
in pisgurukul character u occured at location 5
in pisgurukul character u occured at location 7
in pisgurukul character u occured at location 9
L=eval(input("Enter list"))
ele=eval(input("Enter element to be deleted"))
for i in range(0,len(L)-1):
if ele==L[i]:
L.remove(L[i])
print("List after removing",ele,"is",L)
OUTPUT:
Enter list [1,2,3,4,5,3]
Enter element to be deleted 3
List after removing 3 is [1, 2, 4, 5]
Program – 10 : Extract two list slices out of the given list of numbers. Display and print the
sum of elements of list slice which contains every other element of the list
between indexes 5 to 15. Program should display the average of elements in
second list slice that contains every fourth element of the given list. The list
contains numbers 1 to 20.
L=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
L1=L[5:15:2]
L2=L[::4]
S=0
for i in L1:
S=S+i
Avg=0
for i in L2:
Avg=Avg+i
Avg=Avg/len(L2)
OUTPUT:
the sum of elements of first slice [6, 8, 10, 12, 14] is 50
The Average of elements of second slice [1, 5, 9, 13, 17] is 9.0
Program-11 : Write a program to input two lists and display the maximum element from the
elements of both the list combined, along with the index in its list.
L1=eval(input("enter List1"))
L2=eval(input("enter List2"))
mx1=max(L1)
mx2=max(L2)
if mx1>=mx2:
print(mx1,"The maximum value is in list1 at index",L1.index(mx1))
else:
print(mx2,"The maximum value is in list2 at index",L2.index(mx2))
OUTPUT:
enter List1 [1,2,44,5,6]
enter List2 [45,6,7,8]
45 The maximum value is in list2 at index 0
Program-12 : Write a program to input names of n students and store them in a tuple. Also
input a name from the user and find if this student is present in the tuple or not.
L=[ ]
for i in range(0,n):
ele=input("Enter name")
L.append(ele)
T=tuple(L)
name=input("enter name to be searched")
for i in range(0,n):
if T[i]==name:
print(name, "is present in the tuple",T)
break
else:
print(name, "is not present in the tuple",T)
OUTPUT:
T=eval(input("enter a tuple"))
for el in T:
if T.count(el) > 1:
print("Tuple contains duplicate elements")
break
else:
print("Tuple do not contain any duplicate elements")
OUTPUT :
enter a tuple(10,20,30,40,10,)
Tuple contains duplicate elements
enter a tuple(10,20,30)
Tuple do not contain any duplicate elements
Program-14 : Write a program to create a dictionary with the roll number, name and marks
of n students in a class and displays the names of students who have marks
above 75.
n=int(input("How many students?"))
stu={}
for i in range (1,n+1):
print("Enter details of student",i)
rollno=int(input("Enter roll number"))
name=input("Enter name")
marks=float(input("Enter marks"))
D={"Roll_No":rollno, "Name":name, "Marks":marks}
key="Stu"+str(i)
stu[key]=D
print("Student with marks > 75 are :")
for i in range(1,n+1):
key="Stu"+str(i)
if stu[key]["Marks"]>=75:
print(stu[key])
OUTPUT :
How many students? 3
Enter details of student 1
Enter roll number 11
Enter name aa
Enter marks 88
Enter details of student 2
Enter roll number 12
Enter name bb
Enter marks 66
Enter details of student 3
Enter roll number 13
Enter name cc
Enter marks 99
Student with marks > 75 are :
{'Roll_No': 11, 'Name': 'aa', 'Marks': 88.0}
{'Roll_No': 13, 'Name': 'cc', 'Marks': 99.0}
Program-15 : Write a Python program that takes a value and checks whether the given value
is part of given dictionary or not. If it is, it should print the corresponding key
otherwise print an error message.
D={0:"Zero",1:"One",2:"Two",3:"Three",4:"Four",5:"Five"}
ans='y'
while ans=='y' or ans=='Y':
val=input("Enter value")
print("value",val,end=" ")
for k in D:
if D[k]==val:
print("Exists at ",k)
break
else:
print("Not found")
ans=input("Do you want to check more values")
OUTPUT :