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

Python Revision Tour-2 Worksheet

This document contains 55 programming questions and code snippets to test Python skills. The questions cover a range of Python topics like lists, tuples, dictionaries, strings, conditional statements, loops, functions and more. Students are asked to predict the output or identify errors in the given code snippets.

Uploaded by

muthurupesh2007
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
287 views

Python Revision Tour-2 Worksheet

This document contains 55 programming questions and code snippets to test Python skills. The questions cover a range of Python topics like lists, tuples, dictionaries, strings, conditional statements, loops, functions and more. Students are asked to predict the output or identify errors in the given code snippets.

Uploaded by

muthurupesh2007
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

MAHARISHI VIDYA MANDIR SENIOR SECONDARY SCHOOL CHETPET,

CHENNAI-31
PYTHON REVISION TOUR -2 WORKSHEET
Predict the output
1. ANIMAL={"dog":10,"tiger":5,"elephant":15,"Cow":3}
print("Tiger" not in ANIMAL)
2. EXAM="COMPUTER SCIENCE"
print(EXAM[:12:-2])
3. Tuple1=(10,)
Tuple2=Tuple1*2
print(Tuple2)
4. Debug
30 = num
for k in range(0,num)
IF k%4==0 :
print(k*4)
Else:
print(k+3)
5. lst=[2,4,6,8,10]
for i in range(1,5):
lst[i-1]=lst[i]
for i in range(0,5):
print(lst[i],end=' ')
6. elements=['apple',200,300,'red','blue','grapes']
print(elements[3:5])
print(elements[::-1])
7. exam=[‘english’,’physics’,’chemistry’,’cs’,’biology’]
• To insert subject “maths” as last element
• To display the list in reverse alphabetical order
8. X={'Sunil':190, 'Raju':10, 'Karambir':72, 'Jeevan':115}
print('Jeevan' in X, 190 in X, sep='#')
9. a = 'Python! is amazing!'
a = a.split('!')
b = a[0] + "." + a[1] + "." + a[2]
print (b)
10.Which of the following statement(s) would give an error after
executing the following code?
Q="Humanity is the best quality" # Statement1
print(Q) # Statement2
Q="Indeed.” # Statement3
Q[0]= '#' # Statement4
Q=Q+"It is." # Statement5
(a) Statement 3 (b) Statement 4 (c)Statement 5 d)Statement 4 and 5
11. a=tuple()
a=a + tuple('Python')
print(a)
print(len(a))
b=(10,20,30)
print(len(b))
12.Given the following dictionaries
dict_stud = {"rno" : "53", "name" : ‘Rajveer Singh’}
dict_mark = {"Accts" : 87, "English" : 65}
Which statement will merge the contents of both dictionaries in
dict_stud?
(a) dict_stud + dict_mark (b) dict_stud.add(dict_mark)
dict_stud.merge(dict_mark) (d) dict_stud.update(dict_mark)
13.a= "Year 2022 at All the best"
a = a.split('2')
a = a[0] + ". " + a[1] + ". " + a[3]
print (a)
14.import random
n=random.randint(0,3)
color=['Y','W','B','R']
for i in range (1,n):
print(color[i], end='*')
print( )
15.data = [20,19,19,17,20,19,17,20]
d = {}
for x in data:
if x in d:
d[x]=d[x]+1
else:
d[x]=1
print(d)

16.Str= "BHASHA SANGAM @ 75"


S=Str.partition(" ")
print(S)
17.dic1={'r':'red','g':'green','b':'blue'}
for i in dic1:
print (i, end =' ')
18.MN="Bharat @G20"
print(MN[-2:2:-2])
19.import random
Signal=['Stop','Wait','Go']
for K in range (2,0,-1):

R=random.randrange(K)
print(Signal[R], end='#')

20.tuple1 = (11,22,33,44,55,66)
list1 =list(tuple1)
new_list = []
for i in list1:
if i%2==0 :
new_list.append(i)
new_tuple = tuple(new_list)
print(new_tuple)
21.Which function is used to get list of keys from a dictionary dict in python?
22.Str="I will Succeed"
lis=str.split("")
print(lis)
print(lis[-1])
23.s="PREboardCS*2022!"
j=2
for i in s.split('*'):
k=i[:j]
if k.isupper():
j=j+1
elif k.isdigit():
j=j+2
else:
j=j+3
print(s [ j : : j ] )

24.print("Welcome To My Blog"[2:6][:4]+"Welcome To Myn Blog"[5:9][:-2])

25.Which of the following statement(s) would give an error during the


execution of the following code?
R = {'pno':52,'pname':'Virat', 'expert':['Badminton','Tennis'] ,’score':(77,44)}
print(R) #Statement 1
R['expert'][0]='Cricket' #Statement 2
R['score'][0]=50 #Statement 3
R['pno']=50 #Statement 4
26.[1,2] not in [1,2,3,4] returns_______________
27.L=['One' , 'Two', 'Three', 'Four']
print(len(L)/2*len(L[0]))
28.t1=("Sahodya",[1,2,'3'],'S',(3,4,6),"Exam",10)
print(t1[-5:-3][0]+list(t1[3]))
29.s='Wonders of World'
print(s.count('O') + s.index('o'))
30.a= 6
b = 5.5
sum = a+b
print(sum)
print(type (sum))
31.dic = {}
dic [(1, 2, 4)] = 8
dic [(4, 2, 1)] = 10
dic [1, 2] = 24
sum = 0
print(dic)
for i in dic :
sum = sum + dic[i]
print (sum)
32.dic = {'Nitin' : (21, 'NIIT'), 'Ankit' : (15, 'NIIT')}
print('The original dictionary : ', str(dic))
result= [(key, i, j) for key, (i, j) in dic.items()]
print('The list after conversion : ', str(result))
33.L1 = [7, 2, 3, 4] #Statement 1
L2 = L1 + 2 #Statement 2
L3 = L1 * 2 #Statement 3
L = L1.pop(7) #Statement 4
34.t = 'HELLO'
t1 = tuple(t)
print(t1)
35.x = (1, 2, 3)
y = (3, 4)
t=x+y
print(t)
36. D = {1: 'One', 2: 'Two', 3: 'Three'}
L=[]
for K, V in D.items():
if V[0] == 'T':
L.append (K)
print(L)

37.lst1 = [10, 15, 20, 25, 30]


lst1.insert(3, 4)
lst1.insert(2, 3)
print (lst1[-5])
38.sub = 'PYTHON'
for i in sub:
print (i, ' ', end = ' ')
39.obj1= (10, 20, 30, 40, 50, 60, 70, 80, 90)
print(obj1[3:7:2])
40.L =[10, 20]
L1=[30, 40]
L2=[50, 60]
L.append (L1)
L.extend(L2)
print(L)
41.l1 = [1,2,3,4]
l2 = [1,2,3,4]
print(l1 > l2)
42.t1 = (70, 56, 'Hello', 22, 2, 'Hi', 'The', 'World', 3)
print(t1[2 : 4])
print(t1[- 6])
43.Name= 'PythoN3@1'
R=' '
for x in range(len(Name)):
if Name[x].isupper():
R=R+Name[x].lower()
elif Name[x].islower():
R=R+Name[x].upper()
elif Name[x].isdigit():
R=R+Name[x-1]
else:
R=R+ '#'
print(R)
44.L= [2,3,4,5,6]
print(L[-1:-5])
45.t1=(9,6,7,6)
t2=(2.8,12,20)
print(min(t2),max(t2))
print( min(t1) + max(t2)
46.L=[118,16,[20,30,50],120]
L1=[12,16,17]
L.extend(L1)
print(L[2][2])
print(L)
47.t1=(9,6,1,12)
t2=(10,11,12)
print(t1+t2)
print(t1*2)
print(t2-t1)
48.d={'Name': 'Ram','Subjects':['Eng', 'Physics', 'CS'], 'Marks':[67,78,90]}
print(d['Subjects'])
print(d['Subjects'][2])
49.tupnames=('India', 'Australia',('UK', 'Nepal'), 'Bangladesh')
print(tupnames[5 : ])
print(tupnames[2][1])
50.str = "Python Program"
print(str[3:5])
print(str[-10])
print(str[5:])
print(str[-28])
51.s= 'ComputerExam'
print(s[2]+s[8]+s[1:51])
52.dic = {'a':1, 'b':2, 'c':3, 'd':4}
print(dic)
if 'a' in dic :
del dic['a']
print(dic)
53.L=[6,7,8,9,10]
print(L[2:20])
54.s='OceanView'
print(s[8] +s[2:] +str(len(s)))
55.d={'Bed':145000, 'Almirah':9000,'Chair':1000}
for v in d.keys():
if d[v]>100000:
d[v]-=10000
print(d)

You might also like