ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
x = 0
for i in range(1, 101):
x += i
print(x, x // 2 * 2 == x, x % 2)- A. 5050 True 0
- B. 5050 False 0
- C. 5050 True 1
- D. 5151 True 0
Correct answer: A. 5050 True 0
The sum 1 + 2 + ... + 100 is 5050, which is even, so halving and doubling returns it exactly and the remainder is 0.
More Python Programming questions
- What is printed? python print(','.join(['a', 'b']), ','.join('ab'), '%s' % ['a', 'b'], str(('a',)))
- What is printed? python import math print(math.prod([2, 3, 4]), math.prod([]), math.prod([1.5, 2]), math.prod(range(1, 6)) ==…
- What is printed? python words = ['bb', 'a', 'ccc'] print(max(words), max(words, key=len), min(words, key=len), sorted(words, key=lambda w…
- What is printed? python print(len(f'{1234.5:.0f}'), f'{1234.5:.0f}', f'{1235.5:.0f}', f'{-1234.5:.0f}')
- What is printed? python print(1e3 == 103, int(1e3) is not None, 1e3 // 1 == 103, type(1e3 // 1).name)
- What is printed? python print('%x' % -255, '%o' % 8, '%e' % 0.0, '%.0e' % 12345)