Q: What will be the output of the following Python code? i = 1 while True: if i%3 == 0: break print(i) i + = 1
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
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
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
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
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
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
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
Solution: SyntaxError, True is a keyword and it’s value cannot be changed.
You Have Score    | /8 |