ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
n = 10 ** 6
s = 0
i = 1
while i <= n:
s += n // i
i *= 10
print(s)- A. 1111111
- B. 1111110
- C. 1000000
- D. 1111100
Correct answer: A. 1111111
The loop adds n // 10^k for k = 0 to 6. The terms are 1000000, 100000, 10000, 1000, 100, 10 and 1, which add to 1111111.
More Python Programming questions
- What is printed? python def matmul(A, B, m): return [[sum(A[i][k] B[k][j] for k in range(2)) % m for j in range(2)] for i in range(2)] def…
- What is printed? python n = 12 print(n & 1 == 0, (n & 1) == 0, n & n - 1 == 0, 8 & 7 == 0)
- What is printed on the first line? python print(pow(2, -1, 5), pow(3, -1, 7), pow(2, -3, 9)) try: print(pow(2, -1, 4)) except ValueError…
- What is printed? python import math print(math.comb(100, 50) % 1000, len(str(math.comb(100, 50))), math.perm(5, 2), math.comb(5, 7))
- What is printed? python import math print(math.floor(-0.5), math.ceil(-0.5), math.trunc(-0.5), math.floor(2.999999999999999999))
- What is printed? python print(f'{1234567.891:.2f}', f'{255:#x}', f'{5:03d}', f'{-5:03d}', f'{-5:+04d}')