0% found this document useful (0 votes)
48 views

Class Xi Cs Practical File 2022-23

Uploaded by

rmkathiresan6
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)
48 views

Class Xi Cs Practical File 2022-23

Uploaded by

rmkathiresan6
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/ 18

GRADE : XI

COMPUTER SCIENCE
PRACTICAL FILE
INDEX

Sr.No. List of Program Page no. Date Signature


Write a program to accept the radius
1. of a sphere from the user and display
its area and volume.
Area=πr2 and volume=4πr3

Write a program to accept a


2 number from the user and display
its factorial.

3 Write a program to accept a number


from the user and display whether it
is a palindrome number or not.

4 Write a program to accept a number


from the user and display whether it
is a prime number or not.
5 Write a program to display the
following pattern :

1
1 2
1 23
1 234
1 2345
Sr.No. List of Program Pageno. Date Signature

6 Write a program to display the


following pattern :
1
23
456
7 8 9 10
11 12 13 14 15

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.

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.

9 Write a program to input a list and an


element, and remove all occurrences
of the given element from the list.

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.

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.
Sr.No. List of Program Page no. Date Signature

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.
13 Write a program to check if a tuple
contains any duplicate elements.

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.

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
Program-1 : Write a program to accept the radius of a sphere from the user and display its
area and volume. Area=πr2 and Volume=4πr3
import math
r=int(input("Enter radius of a sphere"))
area=math.pi*r*r
volume=math.pi*r**3
print("The area of sphere is ",area)
print("the volume of sphere is",volume)

OUTPUT :

Enter radius of a sphere 5


The area of sphere is 78.53981633974483
The volume of sphere is 392.6990816987241
Program-2: Write a program to accept a number from the user and display its factorial.

n=int(input("Enter any number"))


fac=1
for i in range(1,n+1):
fac=fac*i
print("Factorial of ",n,"is",fac)

Enter any number4


Factorial of 4 is 24
Program-3: Write a program to accept a number from the user and display whether it is a
palindrome number or not.

num1=int(input("enter any number"))


num2=num1
rev=0
while num1!=0:
rem=num1%10
rev=rev*10+rem
num1=num1//10
if num2==rev:
print(num2,"is a palindrome number")
else:
print(num2,"is not a palindrome number")

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.

n=int(input("enter any number"))


for i in range(2,(n//2)+1):
if n%i==0:
print(n,"is not prime number")
break
else:
print(n,"is a prime number")

OUTPUT :
enter any number12
12 is not prime number

enter any number11


11 is a prime number
Program-5: Write a program to display the following pattern :

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.

st=input("enter any string")


u=l=a=d=s=0
for i in st:
if i.isalpha():
a+=1
if i.isupper():
u=u+1
else:
l=l+1
elif i.isdigit():
d+=1
else:
s+=1
print("No. of alphabets",a)
print("No. of uppercase letters",u)
print("No. of lowercase letters",l)
print("No. of digits",d)
print("No. of symbols",s)

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.

s=input("Enter any string")


c=input("Enter any character")

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

Enter any string: pisgurukul


Enter any character: z
z does not occur in pisgurukul
Program-9: Write a program to input a list and an element, and remove all occurrences of the
given element from the list.

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)

print("the sum of elements of first slice",L1,"is",S)


print("The Average of elements of second slice",L2,"is",Avg)

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.

n=int(input("Enter how many names"))

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:

Enter how many names : 5


Enter name abc
Enter name def
Enter name ghi
Enter name jkl
Enter name lmn
enter name to be searched def
def is present in the tuple ('abc', 'def', 'ghi', 'jkl', 'lmn')
Program-13 : Write a program to check if a tuple contains any duplicate elements.

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 :

Enter value One


value One Exists at 1
Do you want to check more values y
Enter value nine
value nine Not found
Do you want to check more values y
Enter value Five
value Five Exists at 5
Do you want to check more values n

You might also like