Q: What will be the output of the following Python code? for i in range(2.0): print(i)
Solution: Object of type float cannot be interpreted as an integer.
Q: What will be the output of the following Python code? for i in range(int(2.0)): print(i)
Solution: range(int(2.0)) is the same as range(2).
Q: What will be the output of the following Python code snippet? for i in [1, 2, 3, 4][::-1]: print (i)
Solution: [::-1] reverses the list.
Q: What will be the output of the following Python code snippet? for i in ': print (i)
Solution: The string does not have any character to loop over.
Q: What will be the output of the following Python code snippet? x = 2 for i in range(x): x += 1 print (x)
Solution: Variable x is incremented and printed twice.
Q: What will be the output of the following Python code snippet? x = 2 for i in range(x): x -= 2 print (x)
Solution: The loop is entered twice.
You Have Score    | /6 |