CHAPTER 1 – REVISION TOUR - I
PRACTICE QUESTIONS
STATE TRUE OR FALSE
1. Python is a low level language.
2. Python is a free source language.
3. Python converts low level language to high level language.
4. Python is a compiler.
5. Python is case sensitive language.
6. Python was named after famous BBC comedy show
namely Monty Python’s Flying Circus.
7. Python is not a Cross-platform Language.
8. All identifiers in Python are in lower case.
9. An identifier is a user defined name given to a variable or
a constant in a program.
10. Python does not allows same variable to hold different data
literals / data types.
11. Operators with the same precedence are evaluated in right to
left manner.
12. Interactive mode is used when a user wants to run a single line
or one block of code.
13. Script mode is used when the user is working with more than
one single code or a block of code.
14. In Python, a variable may be assigned a value of one type, and
then later assigned a value of a different type.
15. In Python, a variable must be declared before it is assigned a
value.
16. Variable names can be of any length.
17. the complement operator inverts the value of each bit of
the operand
18. print(int(6>7-6-7*4) ) will print boolean value.
19. Logical operator not has highest precedence among all the
logical operators.
20. “is” is a membership operator in python.
21. Following code will produce True as output:
x=10>5>1 and -3<-2<-1
print(x)
22. The value of expression 3/5*(7-2) and 3/(5*(7-2)) is same.
23. The expression 4**3**2 is evaluated as (4**3)**2
24. () have higher precedence that any other operator.
25. print() always inserts a newline after each output.
26. >>> 2*4+36/2-9
In the above expression 36/2 will be evaluated first by python.
APPAN RAJ D PGT- CS/IP 1
27. When syntax error is encountered, Python displays the
name of the error and a small description about the error.
28. "In Python, data type of a variable depends on its value"
29. “Python identifiers are dynamically typed.”
30. (i) -88.0 is the output of the print(3-10**2+99/11)
(ii) range( ) is also a module function
31. Comments in Python begin with a "$" symbol.
32. In a Python program, if a break statement is given in a nested
loop, it terminates the execution of all loops in one go.
33. The math.ceil() function in Python returns the smallest integer
greater than or equal to a given number.
34. In Python, the break statement is used to terminate the entire
program.
35. In Python, the math.pow () function is equivalent to the **
operator for exponentiation.
ASSERTION & REASON
1. A:It is interpreted language.
R: Python programs are executed by an interpreter.
2. A: Python is portable and platform independent.
R:Python program can run on various operating systems
and hardware platforms.
3. A: Python is case-sensitive.
R:Python does not use indentation for blocks and
nested blocks.
4. A: Python program is executed line by line.
R: Python is compiled language.
5. A: Python is an object oriented language
R: Python is a cross platform language
6. A: Python is case-sensitive.
R: NUMBER and number are not same in Python
7. A: Python is a high-level object-oriented programming
language.
R: It can run on different platforms like Windows,Linux, Unix,
and Macintosh.
8. A: An identifier cannot have the same name as of
a keyword.
R: Python interpreter will not be able to differentiate
Between a keyword and an identifier having the
same name as of a keyword.
9. >>>print('Good'+' Morning') #Output :Goodmorning
A : Incorrect Output
R: There is a syntax error
APPAN RAJ D PGT- CS/IP 2
10. A: In Python comments are interpreted and are
shown on the output screen.
R: Single line comments in python starts with #
character
11. A: The math.pow(2,4)gives the output: 16.0
R: The math.pow () method receives two float arguments,
raise the first to the second and return the result.
12. A: Python uses the concept of L-value and R-value,
that is derived from the typical mode of
evaluation on the left and right side of an
assignment statement
R: name = ‘Raj’
In the above code the value ‘Raj’ is fetched (Rvalue)
and stored in the variable named – name (L value)
13. A:>>> print(type((3 + 33)<-(-4 - 44)))
R : As output is True which is a boolean value
14. num1=input("enter a number")
print(num1+2)
A: The above code will give error message when executed.
R: input() returns a string datatype. We cannot add
string data type with a numeric datatype. So,
performing arithmetic operation on it will result in
error.
15. var1=10
var1="hello"
A: The above code is invalid. We cannot assign adata of
different data type to an existing variable.
R: Python supports implicit type casting. So it is
possible to assign a data of different data type to
an existing variable.
16. A: You will get an error if you use double quotes inside a
string that is surrounded by double quotes:
txt = "We are the so-called "Vikings" from the north."
R: To fix this problem, use the escape character \":
17. A: Variables whose values can be changed after they are
created and assigned are called immutable.
R: When an attempt is made to update the value of an
immutable variable, the old variable is destroyed and a
new variable is created by the same name in memory.
18. A: To do arithmetic python uses arithmetic
(+,*,//,**, -, / ,%)
R: Each of these operators is a binary operator
APPAN RAJ D PGT- CS/IP 3
19. A: The relational operator determine the relation among
different operand
R: It returns the Boolean value
20. A:not has a lower priority than non-Boolean operators
R: So not a==b is interpreted as not(a==b)
21. A:The ** operators is evaluated from right to left
R:All operators are left associative
22. A: for the given expression
S1='1'
S2= 1
S3= S1==S2 #value of v3 is False
R: Integer value cannot be compared with string
value.
23. A: following given expression will result into
TypeError
S="XYZ"
v1=[2]
str3=S*v1
R: operator ‘*’ cannot be applied on string
24. A: int(‘A’) The above statement will result into error
R: ‘A’ is not recognised by Python
25. A: a=9, b=int(9.2) Both a and b have same value
R: b is converted to integer explicitly
26. A: In an expression, associativity is the solution to
the order of evaluation of those operators which
clashes due to same precedence.
R: Operators in an expression may have equal
precedence due to which the order of evaluation
cannot be decided just by precedence.
27. A: An example of an infinite loop is : while(1):
R: A loop that continues repeating without aterminating
(ending) condition is an infinite loop.
28. A: The statements within the body of for loopare executed
till the range of values is exhausted.
R: for loop cannot be nested.
APPAN RAJ D PGT- CS/IP 4
29. Analyse the following code:
for i in range(1,4):
for j in range (1,i+1):
print(j,end=’ ’)
print()
A: output is
1
12
123
R: Here, range function will generate value 1,2,3 in the outer
loop and the inner loop will run for each value of “i” used
in outer loop.
30. A: Python provides two looping constructs for and while.
The for is a counting loop and while is a conditional
loop.
R: The while is a conditional loop as we check the
condition first, if it is satisfied then only we can get
inside the while. In case of for it depends upon the
counting statement of index.
31. A: for loop in Python makes the loop easy to calculate
factorial of a number
R: While loop is an indefinite iteration that is used when
a loop repeats unknown number of times and end
when some condition is met.
32. A: range(0,5) will produce list as [0,1,2,3,4]
R: These are the numbers in arithmetic progression (a.p.)
that begins with lower limit 0 and goes up till upper
limit -1.
33. A: To print the sum of following series 1 + 3 + 5…….n. Ravi
used the range function in for loop as follows:
range(1,n+1,2) # 3 parameters
R: In range function first parameter is start value, second
parameter is stop value & the third parameter is step
value.
34. x=0
for i in range(3,9,3):
x = x * 10 + i
print(x)
A: The output of the above code will be 9.
R: The loop will run for 2 times.
APPAN RAJ D PGT- CS/IP 5
35. for i in range(1, 6):
for j in range(1, i):
print("*", end=" ")
print()
A: In a nested loop, the inner loop must terminate
before the outer loop.
R: The above program will throw an error.
36. A: break statement terminates the loop.
R: The else clause of a Python loop executes when the
loop continues normally.
37. A: break statement always appears only in a nested loop.
R: If the break statement is inside the inner loop then it
will terminate the inner loop only.
38. A: break statement terminates the loop it lies within.
R: continue statement forces the next iteration of the loop
to take place, skipping any code in between.
OBJECTIVE TYPE QUESTIONS (MCQ)
1. Python uses ____ to convert its instructions into machine
language.
(a)Interpreter (b)Compiler
(c)Both of the above (d)None of the above
2. Who developed the Python language?
(a) Zim Den (b)Wick van Rossum
(c)Guido Van Rossum (d)NieneStom
3. IDLE stands for __________
(a) Integrated Development Learning
(b) Integrated Development Learning Environment
(c) Intelligent Development Learning Environment
(d) None of the above
4. Python interpreter executes ……………………….statement
(Command) at a time.
(a) Two (b) Three (c) One (d) All command
5. Which of the following is not the feature of python language?
(a) Python is proprietary software.
(b )Python is not case-sensitive.
(c) Python uses brackets for blocks and nested blocks.
(d) All of the above
6. By default, the Python scripts are saved with_____ extension.
(a) .pyp (b).pys (c).py (d)None of the above
7. What is the maximum possible length of an identifier in
python?
(a) 16 (b) 32 (c) 64 (d) None of these
APPAN RAJ D PGT- CS/IP 6
8. Which of the following is not considered a valid identifier in
Python?
(a) Two2 (b) _main (c) hello_rsp1 (d) 2 hundred
9. Which of the following is not a component of the math module in
Python?
(a) ceil() (b) mean() (c) fabs() (d) pi
10. >>> print("I" + "am" + "in" + "school") display
(a) I am in school (b)I Am In School
(c)Iaminschool (d)iaminschool
11. Which of the following is an invalid identifier to be used in
Python?
(a) per%marks (b) _for (c) While (d) true
12. Which of the following statement is correctsyntactically?
(a) print(“Hello” , sep == ‘@’ , end =' ')
(b)print(“Hello” , sep = ‘@’ , end = ' ')
(c)Print(“Hello” , sep = ‘@’ , end = ' ')
(d)print(“Hello” , sep = ‘@’ , end = ' '
13. Which of the following is not a keyword in python?
(a) eval (b) assert (c) nonlocal (d) pass
14. Which of the following is not a valid declaration?
(a) S=12 (b) V="J" (c) F=32.4 (d) H=0254
15. Evaluate the following expression:
>>> not True or not False and False
16. Predict the output of the following code snippet:
for letter in "Python":
if letter =="h":
continue
print(letter,end="")
(a)P (b) Py (c) Python (d) Pyton
17. Which of the following properly expresses the precedence of
operators (using parentheses) in the following expression:
5*3 > 10 and 4+6==11
a) ((5*3) > 10) and ((4+6) == 11))
b) (5*(3 > 10)) and (4 + (6 == 11))
c) ((((5*3) > 10) and 4)+6) == 11
d) ((5*3) > (10 and (4+6))) == 11
18. All keywords in python except True,False and None are in
____?
(a) Lower case (b) Upper case
(c) Capitalized (d) None of the above
19. What is the output of the following :
print(23//9%3, 2**2**2)
(a) 7 64 (b) 2 16 (c) 7 8 (d) 2 64
APPAN RAJ D PGT- CS/IP 7
20. Give the output for the following code:
for i in range(1,10,3):
print(i,sep=”-”,end=”*”)
(a) 1-4-7* (b) 1-4-7-10* (c) 1*4*7* (d) 1*4*7*10
21. Find the invalid identifier from the following
(a) sub%marks (b) age (c) _subname_ (d) subject1
22. Which of the following expressions is an example of type casting?
(a) 4.0+float(6) (b) 5.3+6.3 (c) 5.0+3 (d) None of these
23. Which of the following is an invalid identifier?
(a) CS_class_XII (b) csclass12
(c) _csclass12 (d) 12CS
24. Predict the output of the following code:
>>>import random
>>>random.randint(3.5,7)
(a) Error (b) Any integer between 3.5 and 7, including 7
(c) Any integer between 3.5 and 7, excluding 7
(d) The integer closest to the mean of 3.5 and 7
25. The input() function always returns a value of ……..type.
a) Integer b) float c) string d) Complex
26. To include non-graphic characters in python, which of the
following is used?
(a) Special Literals (b) Boolean Literals
(c) Escape Character Sequence (c) Special Literal – None
27. Which of the following cannot be a variable name?
(a) _init_ (b) in (c) it (d) on
28. Which is valid keyword?
(a) Int (b) WHILE (c) While (d) if
29. Predict the output of the following:
(i) >>>print(10 or 40) (ii) >>> print(22.0//5)
30. Identify the output of the following Python statements.
ans=0
for i in range (11,20,1):
if i %2==0:
ans+=4
else:
ans-=2
print(ans)
(a) 8 (b) 6 (c)10 (d) None
31. Which of the following is an invalid operator in Python?
(a) - (b) //= (c) in (d) =%
32. Which of the following operators is the correct option for
power(a,b)?
(a) a^b (b) a **b (c) a ^^b (d) a^*b
APPAN RAJ D PGT- CS/IP 8
33. Which of the characters is used in python to make a single
line comment?
(a)/ (b) // (c) # (d)!
34. Which of the following is not a core data type in python?
(a)List (b) Dictionary (c) Tuple (d) Class
35. How many times does the following while loop get executed?
K=5
L=36
while K<=L:
K+=6
(a) 4 (b) 5 (c) 6. (d) 7
36. Which of the following functions generates an integer?
(a) uniform( ) (b) randint( )
(c) random( ) (d) None of the above
37. Identify the output of the following Python statements.
b=1
for a in range(1, 10, 2):
b += a + 5
print(b)
(a) 59 (b) 51 (c) 36 (d) 39
38. What will be the output of the following code?
import random
X=[100,75,10,125]
Go=random.randint(0,3)
for i in range(Go):
print(X[i],"$$",end=" ")
(a) 100$$75$$10$$ (b) 75$$10$$125$$
(c) 75$$10$$ (d) 10$$125$$100
39. Which of the following has the highest precedence in
python?
(a)Exponential (b) Addition (c) Parenthesis (d) Division
40. What is math.factorial (4.0)?
(a) 20 (b) 24 (c) 16 (d) 64
41. Identify the invalid variable name from the following.
Adhar@Number, none, 70outofseventy, mutable
42. Which of the following belongs to complex datatype
(a) -12+2k (b) 4.0 (c) 3+4J (d) -2.05I
43. None is a special data type with a single value. It is used to
signify the absence of value in a situation
(a) TRUE (b) FALSE (c) NONE (d) NULL
44. If x=3.123, then int(x) will give ?
(a) 3.1 (b) 0 (c) 1 (d) 3
45. To execute the following code in Python, Which module need to be
imported? >>>print(_______.mean([1,2,3])
APPAN RAJ D PGT- CS/IP 9
46. Find the invalid identifier from the following
(a) Marks@12 (b) string_12 (c)_bonus (d)First_Name
47. Find the invalid identifier from the following
(a) KS_Jpr (b) false (c) 3rdPlace (d) _rank
48. Find the valid identifier from the following:
(a) Tot$balance (b) TRUE (c) 4thdata (d) break
49. Which one of the following is False regarding data types in
Python?
(a) In python, explicit data type conversion ispossible
(b) Mutable data types are those that can bechanged.
(c) Immutable data types are those that cannot bechanged.
(d) None of the above
50. Which statement will give the output as : True from the following
:
a) >>>not -5 b) >>>not 5 c) >>>not 0 d) >>>not(5-1)
51. Evaluate the following expression: 1+(2-3)*4**5//6
(a) -171 (b) 172 (c) -170 (d) 170
52. The correct output of the given expression is:
True and not False or False
(a) False (b) True (c) None (d) Null
53. What will the following expression be evaluated to in Python?
print(6*3 / 4**2//5-8)
(a) -10 (b) 8.0 (c) 10.0 (d) -8.0
54. Evaluate the following expressions:
>>>(not True) and False or True
55. >>> 16 // (4 + 2) * 5 + 2**3 * 4
(a) 42 (b) 46 (c) 18 (d) 32
56. Evaluate the following expression:
True and False or Not True
(a) True (b) False (c) NONE (d) NULL
57. The below given expression will evaluate to
22//5+2**2**3%5
(a)5 (b) 10 (c) 15 (d) 20
58. Which of the following is not a valid identifier name in Python?
a) First_Name b) _Area c) 2nd_num d) While
59. Evaluate the following Python expression
print(12*(3%4)//2+6)
(a)12 (b)24 (c) 10 (d) 14
60. Give the output of the following code:
>>>import math
>>>math.ceil(1.03)+math.floor(1.03)
a) 3 b) -3.0 c) 3.0 d) None of the above
61. >>>5 == True and not 0 or False
(a) True (b) False (c) NONE (d) NULL
APPAN RAJ D PGT- CS/IP 10
62. Predict the output of the following:
from math import*
A=5.6
print(floor(A),ceil(A))
(a) 5 6 (b) 6 5 (c) -5 -6 (d) -6 -5
63. Predict the output of the following code:
import math
print(math.fabs(-10))
(a) Error (b) -10 (c) -10.0 (d) 10.0
64. Which of the following function is used to know the data type of a
variable in Python?
(a) datatype() (b) typeof() (c) type() (d) vartype()
65. Identify the invalid Python statement from the following.
(a) _b=1 (b) b1= 1 (c) b_=1 (d) 1 = _b
66. A=100
B=A
Following the execution of above statements, python has
Created how many objects and how many references?
(a) One object Two reference (b) One object One reference
(c) Two object Two reference (d) Two object One reference
67. What is the output of the following code?
a,b=8/4/2, 8/(4/2)
print(a,b)
(a) Syntax error (b) 1.0,4.0 (c) 4.0,4.0 (d) 4,4
68. Predict output for following code
v1= True
v2=1
print(v1==v2, v1 is v2)
(a) True False (b) False True
(c) True True (d) False False
69. Find output for following given program
a=10
b=20
c=1
print(a !=b and not c)
(a) 10 (b) 20 (c) True (d) False
APPAN RAJ D PGT- CS/IP 11
70. Find output of following given program :
str1_ = "Aeiou"
str2_ = "Machine learning has no alternative"
for i in str1_:
if i not in str2_:
print(i,end='')
(a) Au (b) ou (c) Syntax Error (d) value Error
71. Find output for following given code:
a=12
print(not(a>=0 and a<=10))
(a) True (b) False (c) 0 (d)1
72. What will be value of diff?
c1='A'
c2='a'
diff= ord(c1)-ord(c2)
print(diff)
(a) Error : unsupported operator ‘-’ (b) 32
(c)-32 (d)0
73. What will be the output after the following statements?
x = 27
y=9 (a) 26 11 (b) 25 11
while x < 30 and y < 15: (c) 30 12 (d) 26 10
x=x+1
y=y+1
print(x,y)
74. What output following program will produce
v1='1'
v2= 1
v3=v1==v2
(a) Type Error (b) Value Error
(c)True will be assigned to v3 (d)False will be assigned to v3
75. Which of the following operators has highest precedence:
+,-,/,*,%,<<,>>,( ),**
(a) ** (b) ( ) (c) % (d)-
76. Which of the following results in an error?
(a) float(‘12’) (b) int(‘12’) (c) float(’12.5’) (d) int(‘12.5’)
77. Which of the following is an invalid statement?
(a) xyz=1,000,000 (b) x y z = 100 200 300
(c) x,y,z=100,200,300 (d) x=y=z=1,000,000
78. Which of following is not a decision-making statement?
(a) if-elif statement (b) for statement
(c) if -else statement (d) if statement
APPAN RAJ D PGT- CS/IP 12
79. In a Python program, a control structure:
(a) Defines program-specific data structures
(b) Directs the order of execution of the statements in the
program
(c) Dictates what happens before the program starts and
after it terminates
(d) None of the above
80. Which one of the following is a valid Python if statement?
(a) if a>=9: (b) if (a>=9) (c) if (a=>9) (d) if a>=9
81. if 4+5==10:
print("TRUE")
else:
print("false")
print ("True")
(a) False (b) True (c) false (d) None of these
82. Predict the output of the following code:
X=3
if x>2 or x<5 and x==6:
print("ok")
else:
print(“no output”)
(a) ok (b) okok (c) no output (d) none of above
83. identify one possible output of this code out of the following
options:
from random import*
Low=randint(2,3)
High=randrange(5,7)
for N in range(Low,High):
print(N,end=' ')
(a) 3 4 5 (b) 2 3 (c) 4 5 (d) 3 4 5 6
84. The for loop in Python is an _____________
(a) Entry Controlled Loop (b) Exit Controlled Loop
(c) Both of the above (d) None of the above
85. What abandons the current iteration of the loop?
(a) continue (b) break (c) stop (d) infinite
86. What will the following expression be evaluated to in Python? >>>
print((4.00/(2.0+2.0)))
a)Error b)1.0 c)1.00 d)1
87. Which of the following is not a function/method of the random
module in python?
(a) randfloat( ) (b) randint( )
(c) random( ) (d) randrange( )
APPAN RAJ D PGT- CS/IP 13
88. Given the nested if-else below, what will be the value x
when the source code executed successfully:
x=0
a=5 (a) 0 (b) 4
b=5
if a>0: (c) 2 (d) 3
if b<0:
x=x+5
elif a>5:
x=x+4
else:
x=x+3
else:
x=x+2
print (x)
89. Which of the following is False regarding loops in Python?
(a) Loops are used to perform certain tasks repeatedly.
(b) while loop is used when multiple statements are to
executed repeatedly until the given condition
becomes true.
(c) while loop is used when multiple statements are to
executed repeatedly until the given condition becomes
false
(d) for loop can be used to iterate through the elements
of lists.
90. When does the else statement written after loop executes?
(a) When break statement is executed in the loop
(b) When loop condition becomes false
(c) Else statement is always executed
(d) None of the above
91. Predict the output of the following code:
import statistics as S
D=[4,4,1,2,4]
print(S.mean(D),S.mode(D))
(a) 1 4 (b) 4 1 (c) 3 4 (d) 4 3
APPAN RAJ D PGT- CS/IP 14
92. The following code contains an infinite loop. Which is the
best explanation for why the loop does not terminate?
n = 10
answer = 1
while n > 0:
answer = answer + n
n=n+1
print(answer)
(a) n starts at 10 and is incremented by 1 each time
through the loop, so it will always be positive.
(b) Answer starts at 1 and is incremented by n each
time, so it will always be positive.
(c) You cannot compare n to 0 in the while loop. You
must Compare it to another variable.
(d) In the while loop body, we must set n to False, and
this Code does not do that.
93. What will the following code print?
for i in range(1,4):
for j in range(1,4):
print(i, j, end=' ')
94. What will be the output of the following Python code?
for x in range(1, 4):
for y in range(2, 5):
if x * y > 6:
break
print(x*y, end=“#”)
(a) 2#3#4#4#6#8#6#9#12# (b) 2#3#4#5#4#6#6#
(c) 2#3#4#4#6#6# (d) 2#3#4#6
95. Examine the given Python program and select the purpose of
the program from the following options:
N=int(input("Enter the number"))
for i in range(2,N):
if (N%i==0):
print(i)
(a) To display the proper factors(excluding 1 and the
number N itself)
(b) To check whether N is a prime or Not
(c) To calculate the sum of factors of N
(d) To display all prime factors of the Number N.
APPAN RAJ D PGT- CS/IP 15
96. If A=random.randint(B,C) assigns a random value between 1
and 6(both inclusive) to the identifier A, what should be the
values of B and C, if all required modules have already been
imported?
(a) B=0, C=6 (b) B=0,C=7 (c) B=1,C=7 (d) B=1,C=6
97. The continue statement is used:
(a) To pass the control to the next iterative statement
(b) To come out from the iteration
(c) To break the execution and passes the control to else
statement
(d) To terminate the loop
98. Which of the following is an incorrect logical operator in
python?
(a) not (b) in (c) or (d) and
99. Which of the following symbols are used for comments in
Python?
(a) // (b) & (c) /**/ (d) #
100. print (id(x)) will print_______.
(a) Value of x (b) Datatype of x (c) Size of x (d) Address of x
2 – MARKS
1. Evaluate the following expression:
False and bool(15/5*10/2+1)
2. Predict the output of the following:
M, N, O = 3, 8, 12
N, O, M = O+2, M*3, N-5.
print(N,O,M)
3. If given A=2,B=1,C=3, What will be the output of following
expressions:
(i) print((A>B) and (B>C) or(C>A)) (ii) print(A**B**C)
4. What will be the output of following Python Code:
import random as rd
high=4
Guess=rd.randrange(high)+50
for C in range(Guess, 56):
print(C,end="#")
5. Write the output of the code given below:
p=10
q=20
p*=q//3
p=q**2
q+=p
print(p,q)
APPAN RAJ D PGT- CS/IP 16
7. V, W, X = 20, 15, 10
W, V, X = X-2, V+3, W*2.
print(V,X,W)
8. Evaluate the following expressions:
(a) 5 // 10 * 9 % 3 ** 8 + 8 – 4
(b) 65 > 55 or not 8 < 5 and 0 != 55
9. 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)
10. Evaluate the following: >>> print(15.0/4+(8*3.0))
11. Predict the output of the following:
X,Y,Z = 3,5,-2
X *= Y + Z
Y -= X * 2 + Y
Z += X + Y
print(X, Y, Z)
12. Sona has written the following code to check whether number
is divisible by 3. She could not run the code successfully.
Rewrite the code and underline each correction done in the
code.
x=10
for I range in (a)
if i%3=0:
print(I)
else
pass
13. Rewrite the following code in Python after removing all syntax
error(s). Underline each correction done in the code.
Value=30
for VAL in range(0,Value)
if val%4==0:
print (VAL*4)
Elseif val%5==0:
print (VAL+3)
else
print(VAL+10)
APPAN RAJ D PGT- CS/IP 17
14. Mona has written a code to input a positive integer and display
all its even factors in descending order. Her code is having
errors. Rewrite the correctcode and underline the corrections
made.
n=input("Enter a positive integer: ")
for i in range(n):
if i%2:
if n%i==0:
print(i,end=' ')
Find error in the following code(if any) and correct code by
15. rewriting code and underline the correction;‐
x= int("Enter value of x:")
for in range [0,10]:
if x=y
print( x + y)
else:
print( x‐y)
16. Mithilesh has written a code to input a number and evaluate
its factorial and then finally print the result in the format: “The
factorial of the <number> is <factorial value>” His code is
having errors. Rewrite the correct code and underline the
corrections made.
f=0
num = input("Enter a number:")
n = num
while num> 1:
f = f * num
num -= 1
else:
print("The factorial of : ", n , "is" , f)
17. What is the output of the program given below:
import random
x = random.random()
y= random.randint(0,4)
print(int(x),”:”, y+int(x))
18. Evaluate the following expression and identify the correct
answer:
(i) 18 - (1 + 2) * 5 + 2**5 * 4 (ii) 10 +(5-2) * 4 + 2**3**2
APPAN RAJ D PGT- CS/IP 18
Rewrite the following code after removing the syntactical
19. error(if any).Underline each correction:
X=input("Enter a Number")
If x % 2 =0:
for i range (2*x):
print i
loop else:
print "#"
20. What possible outputs are expected to be displayed on screen
at the time of execution of the program from the following
code? Also specify the maximum value that can be assigned to
each of the variables L and U.
import random
Arr=[10,30,40,50,70,90,100]
L=random.randrange(1,3)
U=random.randrange(3,6)
for i in range(L,U+1):
print(Arr[i],"@",end="")
(i) 40 @50 @ (ii) 10 @50 @70 @90 @
(iii) 40 @50 @70 @90 @ (iv) 40 @100 @
21. Rewrite the following Python program
x=input(“Enter a number”)
if x % 2=0:
print x, “is even”
else if x<0:
print x, “should be positive”
else;
print x “is odd”
22. (i)Find the output generated by the following code:
a=5
b=10
a+=a+b
b*=a+b
print(a,b)
(ii)Answer the following questions from the following code:
num_list=["One","Two","Three","Four"]
for c in num_list:
print(c)
(a) What will be the output of the above code?
(b) How many times the loop executed?
APPAN RAJ D PGT- CS/IP 19
23. Evaluate the following expressions:
a) 7*3+4**2//5-8 b) 7>5 and 8>20 or not 12>4
24. Predict the output of the following code:
num=123
f=0
s=0
while(num > 3):
rem = num % 100
if(rem % 2 != 0):
f += rem
else:
s+=rem
num /=100
print(f-s)
25. Predict the output of the following:
for i in range(4):
if i==4:
break
else:
print(i)
else: print("Welcome")
26. Anu wrote the code that prints the sum of numbers between 1
and the number, for each number till 10.She could not get
proper output.
i=1
while (i <= 10): # For every number i from 1 to 10
sum = 0 # Set sum to 0
for x in range(1,i+1):
sum += x # Add every number from 1 to i
print(i, sum) # print the result
(a) What is the error you have identified in this code?
(b) Rewrite the code by underlining the correction/s.
27. Evaluate the following expressions:
(a) 6+7*4+2**3//5-8 (b) 8<=20 and 11
28. Predict the output of the following code:
X=3
Y=2
Z = -5
X -= Y + Z
Y //= X - Z
Z *= X + Y
print(X, Y, Z)
APPAN RAJ D PGT- CS/IP 20
29. Predict the output of the following:
a=None
b=None
x=4
for i in range(2,x//2):
if x%i==0:
if a is None:
a=i
else:
b=i
break
print(a,b)
30. Predict the output of the following:
for i in range(1, 15, 2):
temp = i
if i%3==0:
temp = i+1
elif i%5==0:
continue
elif i==11:
break
print(temp, end='$')
31. Predict the output of the following:
P,S=1,0
for X in range(-5,15,5):
P*=X
S+=X
if S==0:
break
else:
print(P, "#", S)
32. Predict the output of the following code:
import math,random
print(math.ceil(random.random())
33. Predict the output of the following:
for x in range(1, 4):
for y in range(2, 5):
if x * y > 6:
break
print(x*y, end="#")
APPAN RAJ D PGT- CS/IP 21
34. Predict the output of the following code:
N=5
C=1
while (C<8):
if (C==3 or C==5):
C+=1
continue
print(C,'*',N,'=',C*N)
C+=1
35. Which is NOT the possible output of following program from
given options:
import random
periph = ['Mouse', 'Keyboard', 'Printer', 'Monitor']
for i in range(random.randint(0,2)):
print(periph[i],'*',end=" ")
(a) Mouse *Keyboard * (b) Mouse *Keyboard* Printer*
(c) Mouse * (d) No output
36. What will be the output after the following statements?
x = 27
y = 19
while x < 30 and y > 15:
x=x+1
y=y-1
print(x,y)
37. What will be the output of the following code?
i=1
while True:
if i%3 == 0:
continue
i=i+1
print(i)
38. Predict the output of the following code:
num = 1
while num < 10:
num *= 2
if num == 4:
break
else:
num -= 1
print(num)
APPAN RAJ D PGT- CS/IP 22
39. X, Y = 2, 5
Z=1
while X < 10:
Z += 1
Y *= 2
X=Y-X
else:
print(Z, "#", X)
(a) Discuss the significance of the else clause in the context
of the provided code.
(b) When is the else block executed, and what is the output?
40. Predict the output of the following code:
X, Y = 2, 5
Z=1
while X < 10:
Z += 1
Y *= 2
if Y==20:
break
X=Y-X
else:
print(Z, "#", X)
print(Z,X,Y)
41. A, B, C = 1, 2, 3
for D in range(2):
C += A
B *= D
if D == 2:
A+= 2
break
print(A)
else:
print(A, "#", B, "#", C)
(i) Explain the role of the if statement and the break
statement within the loop
(ii) When is the else block executed in the above code?
(iii) If the break statement is removed from the code, what
output would be produced?
APPAN RAJ D PGT- CS/IP 23