You are on page 1of 1

1 Python Revision Tour-I

1. num^2 is not a valid identifier because special Iteration 3 while (2 > 0) : true
symbols are not allowed. f = 12 * 2 = 24
2. global is a keyword that has pre-defined meaning. n = 2 − 1 = 1
keywords are reserved for special purpose and Iteration 4 while (1 > 0) : true
must not be used as identifier names.
f = 24 * 1 = 24
3. Iteration 1 while (2 < 10) : true n = 1 − 1 = 0
if (2==6) false Iteration 5 while (0 > 0) : false
prints 2 prints 24
i= 2 + 2 = 4
8. while (156 > 3): true
Iteration 2 while (4 < 10) : true
r = 156% 100 = 56
if(4==6) false
if (56% 2 ! = 0) false
prints 4
i= 4 + 2 = 6
else
x = 0 + 56 = 56
Iteration 3 while (6 < 10) : true
if (6==6) true n = 156 / 100 = 1
prints (0 − 56 = − 56)
break
So, output is 2 9. while() loop start with a=3 and end at 11 and
value of ‘a’ is incremented by 2 in each iteration.
4
10. The given program will not print any output
4. for statement encloses one or more statements that
because there is no element in given range.
form the body of the loop, the statements in the loop
repeat continuously a certain number of times. 11. Iteration 1 i = 1 True
e.g. for (variable) in range(start, stop, step): x = x + i+ 2
= 1 + 1 + 2 = 4
5. if (10% 3==0) false Iteration 2 i = 3 True
else : x = 4 + 3 + 2 = 9
prints 13 Iteration 3 i = 5 True
for loop will repeat 3 times, so output will be x = 9 + 5 + 2 = 16
13 Iteration 4 i = 7 False
13 So, output is 16.
13 12. Iteration 1 while (1 < 10) : true
prints 1
6. A = 5 * 3 / /4 + 6 / /8 + 7 − 3 + 9 / /3 + 7 i= 1 * 3 = 3
= 15 / /4 + 6 / /8 + 7 − 3 + 9 / /3 + 7 Iteration 2 while (3 < 10) : true
= 3 + 6 / /8 + 7 − 3 + 9 / /3 + 7 prints 3
i= 3 *3 = 9
= 3 + 0 + 7 − 3 + 9 / /3 + 7
Iteration 3 while (9 < 10) : true
=3+0+7−3+3+7
prints 9
=3+7−3+3+7 i = 9 * 3 = 27
= 10 − 3 + 3 + 7 = 7 + 3 + 7 Iteration 4 while (27 < 10) : false
= 10 + 7 = 17 So, output is 1
7. This program finds the factorial of a number: 3
Iteration 1 while (4 >0) : true 9
f = 1 * 4 = 4 13. The else part is not executed if control breaks out
n = 4 − 1 = 3 of the loop.
Iteration 2 while (3 > 0) : true 14. The else part is executed if control does not break
f = 4 * 3 = 12 out of the loop.
n = 3 − 1 = 2 15. Changes do not happen in-place, rather a new
instance of the string is returned.

You might also like