Python Revision Tour
Python Revision Tour
Q1. What is the output of the following Python Code, Select any one of the following options?
import random
print(int(random.random()*5))
Q3.Identify the correct option to print the value 80 from the list
L=[10,20,40,80,20,5,55]
(i) L[80] (ii) L[4] (iii) L[L] (iv) L[3]
Q4.Consider the following code and answer the questions that follow:
Book={1:'Thriller', 2:'Mystery', 3:'Crime', 4:'Children Stories'}
Library ={'5':'Madras Diaries','6':'Malgudi Days'}
Q5.Ramesh needs to change the title in the dictionary book from ‘Crime’ to ‘Crime
Thriller’. He has written the following command:
Book[‘Crime’]=’Crime Thriller’
i.But he is not getting the answer. Help him choose the correct command:
a. Book[2]=’Crime Thriller’
b. Book[3]=’Crime Thriller’
c. Book[2]=(’Crime Thriller’)
d. Book[3] =(‘Crime Thriller’)
ii. The command to merge the dictionary Book with Library the command would be:
a. d=Book+Library
b. print(Book+Library)
c. Book.update(Library)
d. Library.update(Book)
iii. What will be the output of the following line of code:print(list(Library))
a. [‘5’,’Madras Diaries’,’6’,’Malgudi Days’]
b. (‘5’,’Madras Diaries’,’6’,’Malgudi Days’)
c. [’Madras Diaries’,’Malgudi Days’]
d. [‘5’,’6’]
iv. In order to check whether the key 2 is present in the dictionary Book, Ramesh uses the following
command:
2 in Book
He gets the answer ‘True’. Now to check whether the name ‘Madras Diaries’
exists in the dictionary Library, he uses the following command:
‘Madras Diaries’ in Library
But he gets the answer as ‘False’. Select the correct reason for this:
a. We cannot use the in function with values. It can be used with keys only.
b. We must use the function Library.values() along with the in operator
c. We can use the Library.items() function instead of the in operator
d. Both b and c above are correct.
Q6.Priyank is a software developer with a reputed firm. He has been given the task to computerise the
operations for which he is developing a form which will accept customer data as follows:
i. The data to be entered is :
a. Name b. Age c. Items bought( all the items that the customer bought)
d. Bill amount
ii. Choose the most appropriate data type to store the above information in the given sequence:
a. string, tuple, float, integer b. string, integer, dictionary, float
c. string, integer, integer, float d. string, integer, list, float
iii. Now the data of each customer needs to be organised such that the customer can be identified by
name followed by the age, item list and bill amount. Choose the appropriate data type that will help
Priyank accomplish this task.
a. List b. Dictionary c. Nested Dictionary d. Tuple
iv. Which of the following is the correct way of storing information of customers named
‘Paritosh’ and ‘Bhavesh’ with respect to the option chosen above?
a. a.customers= {‘Paritosh’:24,[‘Printed Paper’, ‘ Penstand’], 3409, ‘Bhavesh’: 45,[‘A4 Rim’,’Printer
Cartridge’, ‘Pen Carton’, ‘Gift Wrap’],8099.99 }
b. customers={‘Paritosh’:[24,[‘Printed Paper’, ‘ Penstand’], 3409],‘Bhavesh’: [45,[‘A4 Rim’,’Printer
Cartridge’, ‘Pen Carton’, ‘Gift Wrap’], 8099.99] }
c. c.customers= [‘Paritosh’:24,‘Printed Paper’, ‘ Penstand’, 3409,‘Bhavesh’: 45,‘A4 Rim’,’Printer
Cartridge’, ‘Pen Carton’, ‘Gift Wrap’,8099.99 ]
d. customers=(‘Paritosh’:24,[‘Printed Paper’, ‘ Penstand’], 3409,‘Bhavesh’: 45,[‘A4 Rim’,’Printer
Cartridge’, ‘Pen Carton’, ‘Gift Wrap’],8099.99 )
iv. In order to calculate the total bill amount for 15 customers,
Priyank
Statement 1. must use a variable of the type float to store the sum.
Statement 2. may use a loop to iterate over the values
a. Both statements are correct.
b. Statement 1 is correct, but statement 2 is not.
c. Both statements ar incorrect.
d. Statement 1 is incorrect but statement 2 is correct.
Q8. Identify the correct statement(s) to product the values between 10 to 20 using range()
(i) range(10,20) (ii) range(10,21) (iii) range(10,19) (iv) range(20)
Q10.Identify the correct option to add new value 50 to existing tuple T (1)
T = (11,22,33,44,55)
(i) T = T + 66 (ii) T = T + 66 (iii) T = T + (66,) (iv) T = T + (66)
Q12. Which is the output of the following python code. Write reason also:
d={}
d[100]=100
d['200']=200
d[100.0]=50
sum=0
print(d)
for i in d:
sum+=d[i]
print(sum)
Q13. What is the minimum and maximum value of 'A' in the following statement.
import random
A=random.randint(2,30)
print(A)
Q14.Ramesh is writing a program to find the factorial of a number. Help him to complete the
program by selecting the correct code :-
fact=__________ #first statement
num=5
while________ #second statement
fact=_________ #third statement
num=_________ #fourth statement
print(“factorial is:”,fact)
Q15.Rohan wants to drive a car but He is unable to drive because his age is below 18.A python code
is written to check his age .identify it is correct or incorrect and write reasons:
Age=input(“enter age:”)
if age<=18:
print(“you are not eligible””)
Q16.Ravi wants to add new student’s record ,Identify the name of function to add new
record:
i)append() ii)add() iii)Sort() iv)rev()
Q17. . Komal wants to display the following output identify what will be used to print the
following output with reason :-
Output:
ROLLNO NAME CLASS SECTION
i) print(“ROLLNONAMECLASSSECTION”,end=” “)
ii) print(“ROLLNO”,” NAME”,”CLASS”,” SECTION”,end=” “)
iii) print(“ROLLNO”,” NAME”,”CLASS”,” SECTION”,sep=” “)
Q18. What will be the output of the following code:-
print((4 > 5) and (2 != 1) or (4 < 9))
Q19. Consider a tuple in python named DAYS = (‘SUN’, ‘MON’, ‘TUES’). Identify
the invalid statement(s) from the given below statements:-
(a) S = DAYS[0] (b) print(DAYS[2]) (c) DAYS[1] = ‘WED’ (d) LIST1 = list(DAYS)
Q21. Both the print statement will produce the same result.(T/F)
L = ["Amit", "Ananya", "Parth"]
print(L[-1])
print(L[-1][-1])
A. del dic["tiger"]
B. dic["tiger"].delete()
C. delete(dic.["tiger"])
D. del(dic.["tiger"])
Q30. What will be the output of the following Python code snippet?
a={1:"A",2:"B",3:"C"}
print(a.get(1,4))
Q31. What will be the output of the following Python code snippet?
a={1:"A",2:"B",3:"C"}
print(a.get(5,4))
Q32. What will be the output of the following Python code snippet?
a={1:"A",2:"B",3:"C"}
a.setdefault(4,"D")
print(a)
#A1
x=12,13,14
y=list(x)+[15,16,17]
print(x,' ',y)
#A2
# What will be the output of the following code?
data = [x for x in range(7)]
temp = [x for x in range(9) if x in data and x%2==1]
print(temp
#A3
T = [11, 12, 13, 14, 15, 16, 17, 18]
print(T.index(15))
print(T[T[T[6]-13]-16])
print(T.pop(-3))
print(T.remove(T[0]))
print(T)
#A4
list1 = ['CoMpScI', 'APPL.MAT', '2021', 'python']
list2 = [1, 2, 3, 4, 5, 6, 7 ]
print ("list1[0][1]: ", list1[0][1:5])
print ("list1[-2][0]: ", list1[-2][0:3] )
print ("list1[-1][1]: ", list1[-1][1:3])
print ("list2[1:5]: ", list2[1:5])
#A5
L=["Class","XII","has",["CS","IP"],["in","the","subject"],"computer","science"]
print (len(L))
print (L[6:])
print (L[3][1].lower())
print (L[::2])
print ("in"in L)
print (L[5][:2]+L[2][1:])
print (L[4][::-1])
#A6
n=3
S="Practice makes a man Perfect"
w_len = [ ]
txt = S.split(" ")
fori in txt:
iflen(i)> n:
w_len.append(i)
print(w_len)
#A7
st="MaKe HeY WhIlE SuN ShInEs"
Dat=list(st)
fori in range(len(Dat)):
if(Dat[i].isupper()):
Dat[i]=Dat[i].lower()
elif(Dat[i].islower()):
Dat[i]=Dat[i].upper()
else :
Dat[i]=Dat[i+1]
print(Dat)
#A8
x="Attitude Decides Altitude"
print(x[:2],x[:-2],x[-2:])
print(x[5],x[3:6])
print(x[1:-4],x[-6:-2])
t="HealTh Is WeaLTH"
l=len(t)
nt= ' '
fori in range(0,l):
if t[i].isupper() :
nt=nt+t[i].lower()+' '
elif t[i].isalpha():
nt=nt+t[i].upper()+' '
else :
nt=nt+'biba'+' '
print(nt)
#A 10
w="Green veGetables Clean Environment"
print(w.find('G',2))
print(w.find('ean'))
print(w.find("Get",2,15))
#A 11
ar=[11,12,13,14,15,16]
fori in range(1,6):
ar[i-1]=ar[i]
fori in range(0,6):
print(ar[i],end=' ')
#A 12
t=('very','long','bad','vacation')
(x,y,z,w)=t
print(x,y,z,w)
t=(w,x,y,z)
print(t)
print(t[0][0]+t[1][1],t[1])
# A 13
dict={}
dict[(1,2,4)]=10
dict[(4,2,1)]=15
dict[(1,2)]=20
s=0
for i in dict:
s+=dict[i]
print(s)
print(dict)
# A 15
Msg1="WeLcOME"
Msg2="GUeSTs"
Msg3=""
for I in range(0,len(Msg2)+1):
if Msg1[I]>="A" and Msg1[I]<="M":
Msg3=Msg3+Msg1[I]
elif Msg1[I]>="N" and Msg1[I]<="Z":
Msg3=Msg3+Msg2[I]
else: Msg3=Msg3+"*"
print Msg3
# A 16
STR = ["90","10","30","40"]
COUNT = 3
SUM = 0
for I in [1,2,5,4]:
S = STR[COUNT]
SUM = float (S)+I
print SUM
COUNT–=1
Given here two lists
Lst1=['This','is','a','dictionary']
Lst2=['This', 'is',['another' ,'Dictionary']]
Find the output produced by :
a. Lst1[3][4:7]
b. Lst2[2][1][2:-2].upper()
Given , L=(‘c’,’s’,’ip’)
a. What is the difference (if any) between x*3 and (x,x,x) ?
b. Differentiate x[1:2] =4 and x[1:2]==4