0% found this document useful (0 votes)
1 views13 pages

083 - Cs - Xii - Python Revision Tour

The document is a Python revision tour consisting of multiple-choice questions, code corrections, and programming tasks. It covers various topics including data types, literals, control structures, and functions in Python. The document also includes examples of expected outputs and explanations for certain programming concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views13 pages

083 - Cs - Xii - Python Revision Tour

The document is a Python revision tour consisting of multiple-choice questions, code corrections, and programming tasks. It covers various topics including data types, literals, control structures, and functions in Python. The document also includes examples of expected outputs and explanations for certain programming concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

PYTHON – REVISION TOUR

1 „Welcome‟ is _______________ literals

Ans. string

2 $ symbol can be used in naming an identifier (True/False)

Ans. False

3 Write any 2 data types available in Python

Ans. int, bool

4 „Division by zero‟ is an example of _______________ error.

Ans. Runtime Error

5 range(1,10) will return values in the range of _____ to _______

Ans. 1 to 9

6 randint(1,10) will return values in the range of _______ to _____

Ans. 1 to 10

7 “Computer Science”[0:6] = ____________


“Computer Science”[3:10] = ____________
“Computer Science”[::-1] = ____________
“Computer Science”[-8:]= ____________

Ans. “Computer Science”[0:6] = Comput


“Computer Science”[3:10] = puter S
“Computer Science”[::-1] = ecneicS retupmoC
“Computer Science”[-8:] = Science

8 Output of : print(“Ok”*4 + “Done”)

Ans. OkOkOkOkDone

9 Output of : print(print(“Why?”))
Ans. Why?
None

10 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
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 : _______________

Ans. C = A//B

11 Can you guess the output?


C = -11%4
print(C)

Ans. 1

12 Write 2 advantages and disadvantages of Python programming language

Ans. Advantages
1) Easy to Use
2) Expressive Language
Disadvantages
1) Slow because of interpreted
2) Not strong on type binding

13 Identify the valid and Invalid identifiers names:


Emp-Code, _bonus, While, SrNo. , for, #count, Emp1, 123Go, Bond007

Ans. Valid: _bonus, While, Emp1,Bond007


Invalid : Emp-code, SrNo., for,#count,123Go

14 Identify the type of literals for each:


(i) 123
(ii) „Hello‟
(iii) „Bye\nSee You‟
(iv) „A‟
(v) 345.55
(vi) 10+4j
(vii) 0x12

Ans. (i) Int


(ii) String
(iii) String
(iv) String
(v) Float
(vi) Complex
(vii) Int
15 What is the size of each string?
(i) „Python‟
(ii) „Learning@\nCS‟
(iii) „\table‟

Ans. (i) 6
(ii) 12
(iii) 5

16 Output of :
(i) True + True =
(ii) 100 + False =
(iii) -1 + True =
(iv) bool(-1 + True) =

Ans. (i) 2
(ii) 100
(iii) 0
(iv) False

17 Output of
(i) 2 * 7 = _____
(ii) 2 ** 7 = _____
(iii) 2**2**3 = _____
(iv) 17 % 20 = _____
(v) not(20>6) or (19>7) and (20==20) = ____

Ans. (i) 14
(ii) 128
(iii) 256
(iv) 17
(v) True

18 Output of :
a,b,c = 20,40,60
b+=10
c+=b
print(a,b,c)

Ans. 20 50 110

19 Write a program to enter 2 number and find sum and product

Ans. n1 = int(input('Enter num1 '))


n2 = int(input('Enter num2 '))
s = n1 + n2
p = n1 * n2
print('Sum=',s)
print('Product =',p)

20 Write a program to enter temperature in Fahrenheit and convert it


in Celsius
Ans. f = int(input('Enter temperature (Fahrenheit) '))
c = (f-32)*5/9
print('Celcus =',c)

21 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
100 =0
50 =1
20 = 0
10 = 1
5 = 0
2 = 0
1 = 0
Hint : use % and // operator (Without Loop / Recursion)

Ans. amount = int(input('Enter Amount '))


n2000 = amount//2000
amount = amount % 2000
n500 = amount//500
amount = amount % 500
n200 = amount//200
amount = amount %200
n100 = amount//100
amount = amount %100
n50 = amount//50
amount = amount %50
n20 = amount//20
amount = amount %20
n10 = amount // 10
amount = amount %10
n5 = amount // 5
amount = amount % 5
n2 = amount//2
amount = amount % 2
n1 = amount//1
amount = amount % 1
print('2000=',n2000)
print('500=',n500)
print('200=',n200)
print('100=',n100)
print('50=',n50)
print('20=',n20)
print('10=',n10)
print('5=',n5)
print('2=',n2)
print('1=',n1)
22 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
c) write statement to check “Sister” is in MyFamily or not d)
write statement to update “Jacky” with “Tiger”
e) write statement remove “Jacky” from MyFamily and also print it
f) write statement to add “Tommy” in MyFamily at the end

Ans. a) print(MyFamily[2])
b) print(MyFamily[::-1])
c) 'Sister' in MyFamily
d) MyFamily[len(MyFamily)-1]='Tiger' OR MyFamily[4]=‟Tiger‟
e) MyFamily.pop()
f) MyFamily.append(„Tommy‟)

23 Consider a Tuple:
Record = (10,20,30,40)
Raj wants to add new item 50 to tuple, and he has written
expression as
Record = Record + 50, but the statement is giving an error, Help
Raj in writing correct expression.
Correct Expression : _______________

Ans. Record = Record + (50,)

24 What is the difference between List and Tuple?

Ans. List is mutable type whereas Tuple is Immutable.

25 What is the difference between List and String?

Ans. List is mutable type whereas String is immutable. List can store
elements of any type like-string, list, tuple, etc. whereas String
can store element of character type only.

26 What is ordered and unordered collection? Give example of each

Ans. Ordered collection stores every elements at index position starts


from zero like List, Tuples, string whereas unordered collection
stores elements by assigning key to each value not by index like
dictionary

27 Consider a Dictionary
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
Ans. (i) print(Employee['Name'])
(ii) Employee['Salary']=90000
(iii) print(Employee.values())

28 Num = 100
Isok = False
print(type(Num)) = _______
print(type(Isok)) = _______

Ans. <class 'int'>


<class 'bool'>

29 Name the Python Library module which need to be imported to


invoke the following function:
a) floor()
b) randrange()
c) randint()
d) sin()

Ans. a) math
b) random
c) random
d) math

30 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)
IF k%4==0:
print (K*4)
Else:
print (K+3)

Ans. To=30
for K in range(0,To):
if K%4==0:
print(K*4)
else:
print(K+3)
31 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
FOR i in range(10)
if i%7=0:
continue

Ans. a=5
work=True
b='hello'
c = a + b
for i in range(10):
if i%7==0:
continue

32 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]


IF Name[0]='S':
print(Name)

Ans. for Name in [„Ramesh‟,‟Suraj‟,‟Priya‟]:


if Name[0]=='S':
print(Name)

33 Rewrite the following code in python after removing all


syntax error(s). Underline each correction done in the code:
a=b=10
c=a+b
While c=<20:
print(c,END="*")
c+=10

Ans. a=b=10
c=a+b
while c<=20:
print(c,end="*")
c+=10

34 Choose the correct possible answer(s)


a = random.randint(1,5)
b = random.randint(1,3)
c = random.randint(2,6)
print(a,b,c)
(i) 2 1 3 (ii) 4 4 4 (iii) 3 2 1 (iv) 5 3 5
Ans. (i) (iv)

35 What is type conversion in Python? What are different types


of conversion? Illustrate with example.

Ans. Type conversion refers to conversion of one data type to another


data type for e.g. string is converted to int. There are 2 types
of conversion:
1) Implicit: in this of conversion, it is automatically done
by the interpreter without user intervention.
Example:
Num = [10,20,30]
print(type(Num[1])) # int
Num[1] = Num[1] + 4.5 # it will automatically convert to
float Print(type(Num[1])) # float
2) Explicit: in this type of conversion, user will convert any type
of value to its desired type. For example string to int.
Example:
num = int(input(„Enter number „))
#in the above code input of string type will be converted
explicitly in int.

36 Fill in the blanks to execute infinite loop:


while _______:
print(“spinning”)

Ans. while True:


print(“spinning”)

37 Write a program to enter any number and check it is divisible by


7 or not

Ans. num = int(input('Enter any number '))


if num % 7 == 0:
print('Divisible by 7')
else:
print('Not divisible by 7')

38 Fill in the blanks to execute loop from 10 to 100 and 10 to


1 (i)
for i in range(______):
print(i)

(ii)
for i in range(_______):
print(i)
Ans. (i)
for i in range(10,101):
print(i)
(ii)
for i in range(10,0,-1):
print(i)

39 What will be the output if entered number (n) is 10 and 11


i=2
while i<n:
if num % i==0:
break
print(i)
i=i+1
else:
print("done")

Ans. If n is 10 then when program control enter in loop the if


condition will be satisfied and break will execute cause loop to
terminate. The else part of while will also be not executed
because loop terminated by break. (NO OUTPUT)
If n is 11 it will print 2 to 10 and then it will execute else
part of while loop and print „done‟ because loop terminate
normally without break

40 What will be the difference in output


(i)
for i in range(1,10):
if i % 4 == 0:
break
print(i)

(ii)

for i in range(1,10):
if i % 4 == 0:

continue
print(i)
Ans. (i)
1
2
3
(ii)
1
2
3
5
6
7
9
10

41 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.
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=”#“)
(i) 10#40#70# (ii) 30#40#50#
(iii) 50#60#70# (iv) 40#50#70#

Ans. Maximum Value of FROM = 3


Maximum Value of TO = 4
Output : (ii)

42 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 minimum and maximum value that can be assigned to the
variable PICKER.
import random
PICKER=random.randint(0,3)
COLORS=["BLUE","PINK","GREEN","RED"]
for I in COLORS:
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

Ans. Minimum Value of PICKER = 0


Maximum Value of PICKER = 3
Output: (i) and (iv)

43 What are the correct ways to generate numbers from 0 to 20


(i)range(20) (ii) range(0,21) (iii) range(21) (iv) range(0,20)

Ans. (ii) And (iii)

44 Which is the correct form of declaration of


dictionary? (i)
Day={1:‟monday‟,2:‟tuesday‟,3:‟wednesday‟}
(ii) Day=(1;‟monday‟,2;‟tuesday‟,3;‟wednesday‟)
(iii) Day=[1:‟monday‟,2:‟tuesday‟,3:‟wednesday‟]
(iv) Day={1‟monday‟,2‟tuesday‟,3‟wednesday‟]

Ans. (i)

45 Choose the correct declaration from the following code:


Info =
({„roll‟:[1,2,3],‟name‟:[„amit‟,‟sumit‟,‟rohit‟]}) List
(ii) Dictionary (iii) String (iv) Tuple

Ans. (iv) Tuple

46 Which is the valid 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}

Ans. (iii)

47 What is/are not true about Python‟s Dictionary?


(i) Dictionaries are mutable
(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

Ans. (ii) and (iv)


48 x="abAbcAba"
for w in x:
if w=="a":
print("*")
else:
print(w)

Ans. *
b
A
b
c
A
b
*

49 Convert the following „for‟ loop using „while‟ loop


for k in range (10,20,5):
print(k)

Ans. k = 10
while k<=20:
print(k)
k+=5

50 Give Output
colors=["violet", "indigo", "blue", "green", "yellow", "orange",
"red"] del colors[4]

colors.remove("blue")
p=colors.pop(3)
print(p, colors)

Ans. orange ['violet', 'indigo', 'green', 'red']

51 Output of following code:


A=10
B=15
S=0
while A<=B:
S = A + B
A = A + 10
B = B + 10
if A>=40:
A = A + 100
print(S)

Ans. 65
52 Output of the following code:
X = 17
if X>=17:
X+=10
else:
X-=10
print(X)

Ans. 27

53 How many times loop will execute:


P=5
Q=35
while P<=Q:
P+=6

Ans. 6 times

54 Find and write the output of the following python


code: Msg="CompuTer"
Msg1=''
for i in range(0, len(Msg)):
if Msg[i].isupper():
Msg1=Msg1+Msg[i].lower()
elif i%2==0:
Msg1=Msg1+'*'
else:
Msg1=Msg1+Msg[i].upper()
print(Msg1)

Ans. cO*P*t*R

55 A=10
B=10
print( A == B) = ?
print(id(A) == id(B) = ?
print(A is B) = ?

Ans. True
True
True

You might also like