You are on page 1of 8

CHOITHRAM SCHOOL MANIK BAGH

INDORE

CBSE CLASS XI 2021-22

COMPUTER SCIENCE PRACTICAL FILE

(CODE: 083)

Submitted to: Submitted by:

Mayank Godbole Sir Varad Gaekwad

XI - A
Computer Science Practical
Varad Gaekwad (XI-A)

S.no Questions and Answers Outputs

1. WAP to reverse the list of elements in place and


print it. (Without using inbuilt functions)

l=eval(input("Enter list elements "))


len_l=len(l)
for i in range (len_l-1 , -1 ,-1):
a=l[i]
l.append(a)
for j in range (len_l,0,-1):
b=l[len_l-j]
l.remove(b)
print ("The reversed list is: ",l)

2. WAP to create a tuple with the squares of elements


of t = (1,2,3,4,5,6,7,8).

t=(1,2,3,4,5,6,7,8)
lst=[]
for i in t:
sq=i**2
lst.append(sq)
tpl=tuple(lst)
print ("The squares of elements in tuple are:",tpl)

1
3. WAP to read roll numbers and marks of 4 students
and create a dictionary from it having roll numbers
as keys and marks as values. (without using eval())
rln1=int(input("Enter your roll number "))
mrk1=int(input("Enter your marks "))

rln2=int(input("Enter your roll number "))


mrk2=int(input("Enter your marks "))

rln3=int(input("Enter your roll number "))


mrk3=int(input("Enter your marks "))

rln4=int(input("Enter your roll number "))


mrk4=int(input("Enter your marks "))

d=dict(((rln1,mrk1),(rln2,mrk2),(rln3,mrk3),(rln4,mrk4)))
print ("The marks of students corresponding to their
roll number is:",d)

4. Consider a List as L = ['Choithram','School','Manik


Bagh','Indore'],
(a) Print ASCII values of first characters of each
element of the list.
(b) Create a dictionary having elements of L as keys
and sum of ASCII values
of each letter of the element as value to
corresponding elements.

(a) L = ['Choithram','School','Manik Bagh','Indore']


for i in L:
ascii_val = ord(i[0])
print ("The ascii values of",i[0],"is",ascii_val)

2
(b) L = ['Choithram','School','Manik Bagh','Indore']
d={}
for i in L:
sum_ascii=0
for j in i:
ascii_val = ord(j)
sum_ascii = sum_ascii + ascii_val
d [i] = sum_ascii
print (d)
5. WAP to count the frequency of a given element in a
tuple of numbers.
t=eval(input("Enter tuple elements "))
ch=int(input("Enter a number "))
cnt=0
for i in t:
if i==ch:
cnt=cnt+1
print("The frequency of the element entered is:",cnt)

6. WAP to create a dictionary contains details of two


workers with their names as keys and other details
(age, gender and location) in the form of a
dictionary
p1=input("Enter your name ")
age1=int(input("Enter your age "))
gnd1=input("Enter your gender ")
loc1=input("Enter your location ")
p2=input("Enter your name ")
age2=int(input("Enter your age "))
gnd2=input("Enter your gender ")
loc2=input("Enter your location ")
d=dict(((p1,{"Age":age1,"Gender":gnd1,"Location":loc1}),(
p2,{"Age":age2,"Gender":gnd2,"Location":loc2})))
print (d)

3
7. Consider the following list and WAP to perform the
following operations on the list- L =
[1,3,5,7,9,2,4,6,8,10]
(a) Swap the elements on odd positions with the
elements on even positions.
(b) Print the subtraction of sum of the elements on
even positions from the
sum of the elements on odd positions

(a) L = [1,3,5,7,9,2,4,6,8,10]
len_L = len(L)
for i in L:
a=L.index(i)
if a%2 == 0:
b=a+2
L.insert(b,i)
L.remove(i)
print (L)

(b) L = [1,3,5,7,9,2,4,6,8,10]
so=0
se=0
for i in L:
a=L.index(i)
if a%2==0:
so=so+i
else:
se=se+i
rint ("The difference is:",(se-so))

4
8. WAP to print sum of forward index and sum of
reverse index of elements of the given list.
l=eval(input("Enter list elements "))
sf=0
sb=0
for i in l:
a=l.index(i)
sf=sf+a
for j in l:
b=l.index(j) - len(l)
sb=sb+b
print ("The sum of forward indices is:",sf)
print ("The sum of backward indices is:",sb)

9. Consider the following list and WAP to perform the


following operations on the tuple- t =
(10,20,30,40,50,60,70,80,90,100)
(a) Delete all elements of the tuple in odd positions.
(b) Print the sum of –ve indices of all the elements
of the modified tuple after the above operation.

(a) t = (10,20,30,40,50,60,70,80,90,100)
lst=list(t)
lstr=[]
for i in lst:
a=lst.index(i)
if a%2!=0:
lst.pop(a)
lst.insert(a," ")
for j in lst:
cnt=lst.count(" ")
for k in range (cnt):
lst.remove(" ")
t=tuple(lst)
print (t)

5
(b) t = (10,20,30,40,50,60,70,80,90,100)
lst=list(t)
lstr=[ ]
for i in lst:
a=lst.index(i)
if a%2!=0:
lst.pop(a)
lst.insert(a," ")
for j in lst:
cnt=lst.count(" ")
for k in range (cnt):
lst.remove(" ")
s=0
for k in lst:
ind_lst=lst.index(k)-len(lst)
s=s+ind_lst
print ("The sum of negative indices is:",s)

10. WAP to arrange the elements of the list in


descending order. (Without using the built -in
function.)
l=eval(input("Enter list elements "))
lst=[ ]
i=len(l)
while i>0:
for a in l:
cntr=0
for b in l:
if a<=b:
cntr=cntr+1

if cntr==len(l):
lst.insert(0,a)
l.remove(a)
i=i-1
print ("The list in descending order is:",lst)
6

You might also like