ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
i = 0
while (i := i + 1) < 4:
pass
print(i)- A. 3
- B. 5
- C. 0
- D. 4
Correct answer: D. 4
The walrus assigns i each time the condition runs. The loop stops when i reaches 4, the first value that fails the test, so the printed value is 4.
More Python Programming questions
- What is printed? python print(float('nan') < 0, float('inf') > 10 300, -float('inf') < -10 300)
- What is printed? python print(10 309 > float('inf'), end=' ') try: float(10 309) except OverflowError as e: print(e)
- What is printed? python from collections import Counter d = {'a': 1, 'b': 2} v = d.values() d['c'] = 3 print(len(v), list(v))
- What is printed? python print(frozenset([1, 2]) == {1, 2}, {frozenset([1]): 'x'}[frozenset([1])])
- What is printed? python a = [1, 2, 3] r = a.reverse() print(r, a)
- What is printed? python t = (1) u = (1,) print(type(t).name, type(u).name, len(u))