ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
n = int('9' * 30)
print(len(str(n + 1)), (n + 1) - 10**30)
  1. A. 31 0
  2. B. 30 0
  3. C. 31 1
  4. D. 30 -1

Correct answer: A. 31 0

n is 10**30 - 1, so n + 1 is 10**30, which has 31 digits. Python integers are unbounded, so the subtraction gives exactly 0 with no overflow.

More Python Programming questions

Exams that ask this topic