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(_)))))
- A. 40951 5
- B. 40950 5
- C. 40951 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
- What is printed? python print('%s' % (1,), '%s' % ((1,),), '%r' % ((1, 2),))
- What is printed? python print(1 if True else 0 or 2, not 0 or 3, (not 0) or 3, 0 or '' or None)
- What is printed? python print(max(map(str, [9, 10, 2])), max([9, 10, 2]), min(map(int, ['10', '9'])))
- What is printed? python x = 0.1 3 y = 0.3 print(x == y, abs(x - y) < 1e-15, round(x, 15) == round(y, 15), x - y)
- What is printed? python print('ß'.isupper(), 'Dž'.istitle(), 'Dž'.isupper(), '1A'.isupper())
- What is printed? python print(f'{270:,}'[:8], len(f'{270:,}'), str(270)[-3:], ('%d' % 270)[-3:])