Test Series - python

Test Number 17/108

Q: What will be the output of the following Python code?

i = 1
while True:
    if i%3 == 0:
        break
    print(i)
 
    i + = 1
A. 1 2
B. 1 2 3
C. error
D. none of the mentioned
Solution: SyntaxError, there shouldn’t be a space between + and = in +=.
Q: What will be the output of the following Python code?

i = 1
while True:
    if i%0O7 == 0:
        break
    print(i)
    i += 1
A. 1 2 3 4 5 6
B. 1 2 3 4 5 6 7
C. error
D. none of the mentioned
Solution: Control exits the loop when i becomes 7.
Q: What will be the output of the following Python code?

i = 5
while True:
    if i%0O11 == 0:
        break
    print(i)
    i += 1
A. 5 6 7 8 9 10
B. 5 6 7 8
C. 5 6
D. error
Solution: 0O11 is an octal number.
Q: What will be the output of the following Python code?

i = 5
while True:
    if i%0O9 == 0:
        break
    print(i)
    i += 1
A. 5 6 7 8
B. 5 6 7 8 9
C. 5 6 7 8 9 10 11 12 13 14 15 ….
D. error
Solution: 9 isn’t allowed in an octal number.
Q: What will be the output of the following Python code?

i = 1
while True:
    if i%2 == 0:
        break
    print(i)
    i += 2
A. 1
B. 1 2
C. 1 2 3 4 5 6 …
D. 1 3 5 7 9 11 …
Solution: The loop does not terminate since i is never an even number.
Q: What will be the output of the following Python code?

i = 2
while True:
    if i%3 == 0:
        break
    print(i)
    i += 2
A. 2 4 6 8 10 …
B. 2 4
C. 2 3
D. error
Solution: The numbers 2 and 4 are printed. The next value of i is 6 which is divisible by 3 and hence control exits the loop.
Q: What will be the output of the following Python code?

i = 1
while False:
    if i%2 == 0:
        break
    print(i)
    i += 2
A. 1
B. 1 3 5 7 …
C. 1 2 3 4 …
D. none of the mentioned
Solution: Control does not enter the loop because of False.
Q: What will be the output of the following Python code?

True = False
while True:
    print(True)
    break
A. True
B. False
C. None
D. none of the mentioned
Solution: SyntaxError, True is a keyword and it’s value cannot be changed.

You Have Score    /8