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

Python Revision Tour

This document contains a Python revision tour activity with multiple choice questions related to Python concepts like dictionaries, lists, tuples, loops, conditional statements etc. The questions cover basic syntax and usage of these concepts. The activity aims to help students revise Python fundamentals.

Uploaded by

Subramanian KR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
234 views

Python Revision Tour

This document contains a Python revision tour activity with multiple choice questions related to Python concepts like dictionaries, lists, tuples, loops, conditional statements etc. The questions cover basic syntax and usage of these concepts. The activity aims to help students revise Python fundamentals.

Uploaded by

Subramanian KR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

PYTHON REVISION TOUR – ACTIVITY

Q1. What is the output of the following Python Code, Select any one of the following options?
import random
print(int(random.random()*5))

Q2.Which is the correct dictionary declaration?


i) d1={1:'January',2='February',3:'March'}
ii) d2=(1:'January',2:'February',3:'March'}
iii) d3={1:'January',2:'February',3:'March'}
iv) d4={1:January,2:February,3:March}

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.

Q7. Which of the following is valid logical operator:


(i) && (ii) > (iii) and (iv) ==

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)

Q9. What will be the output of following Python code?


d={'Name':'Raj','Age':17}
d2=d.copy()
print(id(d)==id(d2))

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)

Q11. Write the output of the following code : import random


for i in range(random.randint(2,2)):
print(i)

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 &gt; 5) and (2 != 1) or (4 &lt; 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)

Q20. Which of the following is valid variable name:-


(a) Student name (b) 3Number (c) %name% (d) Block_number

Q21. Both the print statement will produce the same result.(T/F)
L = ["Amit", "Ananya", "Parth"]
print(L[-1])
print(L[-1][-1])

Q22. Write the output of the following:


A = list(tuple(“Python”))
print(A)
Q23. Write the output of the following :
>>> t1=(1,2,3,4,5,6,7)
>>> t1[t1[1]] + t1[t1[-4]]

Q24. What type of error is returned by following code :


a=(“Amit”, “Sumit”,”Ashish”,”Sumanta”)
print(a.index(“Suman”))

Q25. Write the output of the following.


a=(23,34,65,20,5)
print(a[0]+a.index(5))

Q26. What will be the output of above Python code?


d1={"abc":5,"def":6,"ghi":7}
print(d1[0])
Q27. What will the below Python code do?
dict={"Phy":94,"Che":70,"Bio":82,"Eng":95}
dict.update({"Che":72,"Bio":80})
Q28. What will be the output of above Python code?
d1={"abc":5,"def":6,"ghi":7}
print(d1[0])
Q29. Which of the following will delete key_value pair for key="tiger" in dictionary?
dic={"lion":"wild","tiger":"wild","cat":"domestic","dog":"domestic"}

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)

Q33. What will be the output of the following Python code?


a={1:"A",2:"B",3:"C"}
b=a.copy()
b[2]="D"
print(a)

Q34. What will be the output of the following Python code?


a={1:5,2:3,3:4}
a.pop(3)
print(a)

Q35. What is the output of the following code?


a={1:"A",2:"B",3:"C"}
for i,j in a.items():
print(i,j,end=" ")

#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()

What is the output of the following code snippet?


mylst=[21,22,23]
print((mylst+[2,11,6])[-4])
print((mylst+[3,24,2])[-3] - (mylst+[1,34,6])[-2])

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

What will be the output for the following code ?


lst1,lst2,lst3=('a','b','c'),('a','b','c'),('a','b','c')
print(a is b)
print(a==b)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy