ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(sum(map(int, str(2 ** 100))))
- A. 124
- B. 115
- C. 100
- D. 2
Correct answer: B. 115
Converting 2**100 to a string gives its decimal digits, and summing their integer values gives the digit sum 115. The number has 31 digits, so this stays within the int-to-str limit.
More Python Programming questions
- What is printed? python print(bin(12345).count('1'), len(bin(12345)) - 2)
- What is printed? python print(int(float('1e3')), int('12'))
- What is printed? python print('%5.2f|%-4d|%04x' % (3.14159, 7, 255))
- What is printed? python a = {1, 2, 3, 4} b = {3, 4, 5} print(a ^ b, a - b, b <= a, a | b == {1, 2, 3, 4, 5})
- What is printed? python print(int(2.675 100), round(2.675, 2))
- What is printed? python print(-7.5 // 2, -7.5 % 2)