ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(sum(1 for i in range(1, 1001) if '7' in str(i)))
- A. 270
- B. 272
- C. 271
- D. 300
Correct answer: C. 271
Among 0 to 999 there are 9**3 = 729 numbers with no 7 digit, so 1000 - 729 = 271 numbers contain a 7. The number 1000 has no 7, so the count stays at 271.
More Python Programming questions
- What is printed? python print(int(str(12345)[::-1]) - 12345, 12345 - int(str(12345)[::-1]))
- What is printed? python print(len(bin(-1)), len(hex(255)), oct(64))
- What is printed? python print(int('12abc', 16), int('ABC', 16) == 0xabc, int('1000000') == 106)
- What is printed? python print('%s' % None, '%r' % None, '%d' % True)
- What is printed? python print(str(3) 2 + str(3 2), int(str(3) 2) + 3 2)
- What is printed? python print(10 // 3 3 + 10 % 3 == 10, -10 // 3 3 + -10 % 3 == -10)