12 CS WorkSheet - Fundamental
12 CS WorkSheet - Fundamental
12 CS WorkSheet - Fundamental
com
WORKSHEET
PYTHON – REVISION TOUR
1 „Welcome‟ is _______________ literals
2 $ symbol can be used in naming an identifier (True/False)
3 Write any 2 data types available in Python
4 „Division by zero‟ is an example of _______________ error.
5 range(1,10) will return values in the range of _____ to _______
6 randint(1,10) will return values in the range of _______ to _____
“Computer Science”[0:6] = ____________
“Computer Science”[3:10] = ____________
7
“Computer Science”[::-1] = ____________
“Computer Science”[-8:]= ____________
8 Output of : print(“Ok”*4 + “Done”)
9 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
10 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 : _______________
Output of
(i) 2 * 7 = _____
(ii) 2 ** 7 = _____
17 (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
18 b+=10
c+=b
print(a,b,c)
19 Write a program to enter 2 number and find sum and product
Write a program to enter temperature in Fahrenheit and convert it
20
in Celcius
Write a program to enter any money and find out number of
denominations can be used to make that money. For e.g. if the money
entered is 2560
Then output should be
2000 = 1
500 = 1
200 = 0
21 100 =0
50 =1
20 = 0
10 = 1
5 = 0
2 = 0
1 = 0
Hint : use % and // operator
Consider a list:
MyFamily = [“Father”,”Mother”,”Brother”,”Sister”,”Jacky”]
for i in range(1,10):
if i % 4 == 0:
continue
print(i)
What possible outputs(s) are expected to be displayed on screen at
the time of execution of the program from the following code? Also
specify the maximum values that can be assigned to each of the
variables FROM and TO.
41
www.python4csip.com
import random
AR=[20,30,40,50,60,70];
FROM=random.randint(1,3)
TO=random.randint(2,4)
for K in range(FROM,TO+1):
print (AR[K],end=”#“)
import random
PICKER=random.randint(0,3)
COLORS=["BLUE","PINK","GREEN","RED"]
for I in COLORS:
42 for J in range(1,PICKER):
print(I,end="")
print()
(i) (ii)
BLUE BLUE
PINK BLUEPINK
GREEN BLUEPINKGREEN
RED BLUEPINKGREENRED
(iii) (iv)
PINK BLUEBLUE
PINKGREEN PINKPINK
PINKGREENRED GREENGREEN
REDRED
What are the correct ways to generate numbers from 0 to 20
43
range(20) (ii) range(0,21) (iii) range(21) (iv) range(0,20)
Which is the correct form of declaration of dictionary?
(i) Day={1:‟monday‟,2:‟tuesday‟,3:‟wednesday‟}
44 (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:
45 Info = ({„roll‟:[1,2,3],‟name‟:[„amit‟,‟sumit‟,‟rohit‟]})
List (ii) Dictionary (iii) String (iv) Tuple
Which is the valid dictionary declaration?
i) d1={1:'January',2='February',3:'March'}
46 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
47 (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
x="abAbcAba"
48 for w in x:
if w=="a":
www.python4csip.com
print("*")
else:
print(w)
Convert the following ‘for’ loop using ‘while’ loop
49 for k in range (10,20,5):
print(k)
Give Output
colors=["violet", "indigo", "blue", "green", "yellow", "orange", "red"]
50 del colors[4]
colors.remove("blue")
p=colors.pop(3)
print(p, colors)
Output of following code:
A=10
B=15
S=0
while A<=B:
51 S = A + B
A = A + 10
B = B + 10
if A>=40:
A = A + 100
print(S)
Output of the following code:
X = 17
if X>=17:
52 X+=10
else:
X-=10
print(X)
How many times loop will execute:
P=5
53 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():
54 Msg1=Msg1+Msg[i].lower()
elif i%2==0:
Msg1=Msg1+'*'
else:
Msg1=Msg1+Msg[i].upper()
print(Msg1)
A=10
B=10
55 print( A == B) = ________
print(id(A) == id(B) = ________
print(A is B) = ________