PYTHON REVISION TOUR- WORKSHEET
1 “Welcome” is literals
2 $ symbol can be used in naming an identifier (True/False)
3 Write any 2 data types available in Python
“Computer Science”[0:6] =
4 “Computer Science”[3:10] =
“Computer Science”[::-1] =
“Computer Science”[-8:]=
5 Output of : print(“Ok”*4 + “Done”)
6 Output of : print(print(“Why?”))
Raj was working on application where he wanted to divide the two
number (A and B), he has written the expression as C = A/B, on
execution he entered 30 and 7 and expected answer was 4 i.e. only
7 integer part not in decimal, but the answer was 4.285 approx, help
Raj to correct his expression and achieving the desired output.
Correct Expression :
Can you guess the output?
C = -11%4
8
print(C)
9 Write 2 advantages and disadvantages of Python programming language
10 Identify the valid and Invalid identifiers names:
Emp-Code, _bonus, While, SrNo. , for, #count, Emp1, 123Go, Bond007
Identify the type of literals for each:
(i) 123
(ii) “Hello”
11 (iii) “Bye\nSee You”
(iv) “A”
(v) 345.55
(vi) 10+4j
(vii) 0x12
What is the size of each string?
(i) “Python”
12
(ii) “Learning@\nCS”
(iii) “\table”
Output of :
(i) True + True =
13 (ii) 100 + False =
(iii) -1 + True =
(iv) bool(-1 + True) =
Output of
(i) 2 * 7 =
(ii) 2 ** 7 =
14 (iii) 2**2**3 =
(iv) 17 % 20 =
(v) not(20>6) or (19>7) and (20==20) =
Output of :
a,b,c = 20,40,60
15 b+=10
c+=b
print(a,b,c)
Write a function, lenLines(STRING), that takes a string as an
16
argument and returns a tuple containing length of each word of a
string.
For example, if the string is " let us learn Python", the
tuple will have ( 3, 2, 5, 6)
Consider a list:
MyFamily = [“Father”,”Mother”,”Brother”,”Sister”,”Jacky”]
a) write statement to print “Brother”
b) write statement to print all items of list in reverse order
17 c) write statement to check “Sister” is in MyFamily or not
d) write statement to update “Jacky” with “Tiger”
e) write statement to remove “Jacky” from MyFamily and also print it
f) write statement to add “Tommy” in MyFamily at the end
Consider a Tuple:
Record = (10,20,30,40)
Raj wants to add new item 50 to tuple, and he has written
18 expression as
Record = Record + 50, but the statement is giving an error, Help
Raj in writing correct expression.
Correct Expression :
19 What is the difference between List and Tuple?
20 What is the difference between List and String?
21 What is ordered and unordered collection? Give example of each
Consider a Dictionary
22
Employee = {“Empno‟:1,‟Name‟:‟Snehil‟,‟Salary‟:80000}
Write statements:
(i) to print employee name
(ii) to update the salary from 80000 to 90000
(iii)to get all the values only from the dictionary
Num = 100
Isok = False
23 print(type(Num)) =
print(type(Isok)) =
Rewrite the following code in python after removing all syntax
error(s). Underline each correction done in the code.
30=To
for K in range(0,To)
24
IF k%4==0:
print (K*4)
Else:
print (K+3)
Rewrite the following code in python after removing all syntax
error(s). Underline each correction done in the code:
a=5
work=true
b=hello
c=a+b
25
FOR i in range(10)
if i%7=0:
continue
Rewrite the following code in python after removing all syntax
error(s). Underline each correction done in the code:
for Name in [Ramesh,Suraj,Priya]
26
IF Name[0]='S':
print(Name)
Rewrite the following code in python after removing all syntax
error(s). Underline each correction done in the code:
a=b=10
27 c=a+b
While c=<20:
print(c,END="*")
c+=10
What is type conversion in Python? What are different types of
28
conversion? Illustrate with example.
Fill in the blanks to execute infinite loop:
29 while :
print(“spinning”)
Write a function countMy(SUBJECT) in Python, that takes the
30
dictionary, SUBJECT as an argument and displays the names (in
uppercase) of the subjects whose names are longer than 5 characters.
For example, Consider the following dictionary
SUBJECT={1:"Hindi",2:"Physics",3:"Chemistry",4:"cs",5:"Math"}
The output should be:
HINDI
PHYSICS
CHEMISTRY
Fill in the blanks to execute loop from 10 to 100 and 10 to 1
(i)
for i in range( ):
print(i)
31
(ii)
for i in range( ):
print(i)
What will be the output if entered number (n) is 10 and 11
i=2
while i<n:
if num % i==0:
break
32
print(i)
i=i+1
else:
print("done")
What will be the difference in output
(i)
for i in range(1,10):
if i % 4 == 0:
break
print(i)
33
(ii)
for i in range(1,10):
if i % 4 == 0:
continue
print(i)
Which is the correct form of declaration of dictionary?
(i) Day={1:‟monday‟,2:‟tuesday‟,3:‟wednesday‟}
34 (ii) Day=(1;‟monday‟,2;‟tuesday‟,3;‟wednesday‟)
(iii) Day=[1:‟monday‟,2:‟tuesday‟,3:‟wednesday‟]
(iv) Day={1‟monday‟,2‟tuesday‟,3‟wednesday‟]
Choose the correct declaration from the following code:
35 Info = ({“roll‟:[1,2,3],‟name‟:[“amit‟,‟sumit‟,‟rohit‟]})
(i)List (ii) Dictionary (iii) String (iv) Tuple
Which is the valid dictionary declaration?
i) d1={1:'January',2='February',3:'March'}
36 ii) d2=(1:'January',2:'February',3:'March'}
iii) d3={1:'January',2:'February',3:'March'}
iv) d4={1:January,2:February,3:March}
What is/are not true about Python’s Dictionary?
(i) Dictionaries are mutable
37 (ii) Dictionary items can be accessed by their index position
(iii) No two keys of dictionary can be same
(iv) Dictionary keys must be of String data type
Find the output:
x="abAbcAba"
for w in x:
38 if w=="a":
print("*")
else:
print(w)
Convert the following “for” loop using “while” loop
39 for k in range (10,20,5):
print(k)
Give Output
40 colors=["violet", "indigo", "blue", "green", "yellow", "orange", "red"]
del colors[4]
colors.remove("blue")
p=colors.pop(3) print(p, colors)
Find the Output of the following code:
A=10
B=15
S=0
while A<=B:
41 S = A + B
A = A + 10
B = B + 10
if A>=40:
A = A + 100
print(S)
Find the Output of the following code:
X = 17
if X>=17:
42 X+=10
else:
X-=10
print(X)
How many times loop will execute:
P=5
43 Q=35
while P<=Q:
P+=6
Find and write the output of the following python code:
Msg="CompuTer"
Msg1=''
for i in range(0, len(Msg)):
if Msg[i].isupper():
44 Msg1=Msg1+Msg[i].lower()
elif i%2==0:
Msg1=Msg1+'*'
else:
Msg1=Msg1+Msg[i].upper()
print(Msg1)
A=10
B=10
45 print( A == B) = ?
print(id(A) == id(B)) = ?
print(A is B) = ?