Professional Documents
Culture Documents
INDORE
(CODE: 083)
XI - A
Computer Science Practical
Varad Gaekwad (XI-A)
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 "))
d=dict(((rln1,mrk1),(rln2,mrk2),(rln3,mrk3),(rln4,mrk4)))
print ("The marks of students corresponding to their
roll number is:",d)
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)
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)
(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)
if cntr==len(l):
lst.insert(0,a)
l.remove(a)
i=i-1
print ("The list in descending order is:",lst)
6