ProgrammingVery hardJEE Main · CAT placement

What is printed?

What is printed?
print(sum(1 for _ in range(10**5) if '7' in str(_)), len(str(sum(1 for _ in range(10**5) if '7' in str(_)))))
  1. A. 40951 5
  2. B. 40950 5
  3. C. 40951 4
  4. D. 40951 6

Correct answer: A. 40951 5

Numbers from 0 to 99999 with no 7 have five digits chosen from nine digits, which is 9**5 = 59049. So 100000 - 59049 = 40951 contain a 7, and that count has five digits.

More Python Programming questions

Exams that ask this topic