ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
x, rev = 1200, 0
while x:
rev = rev * 10 + x % 10
x //= 10
print(rev, int(str(1200)[::-1]), str(1200)[::-1] == '0021')- A. 0021 21 True
- B. 21 21 False
- C. 21 21 True
- D. 21 1200 True
Correct answer: C. 21 21 True
The digit loop drops leading zeros naturally, so reversing 1200 gives 21 rather than 0021. The string reversal keeps the zeros, so the string comparison with '0021' is True.
More Python Programming questions
- What is printed? python print(int('zz', 36), format(1295, 'x'), int('1295', 10) == 1295, int('zz', 36) == 35 36 + 35)
- What is printed? python print([n for n in range(100, 1000) if sum(int(d) 3 for d in str(n)) == n])
- What is printed? python print(bin(37).count('1'), bin(37)[2:].count('0'), (37).bitlength() - bin(37).count('1'))
- What is printed? python x, count = 0b1011011, 0 while x: x &= x - 1 count += 1 print(count, bin(0b1011011).count('1'))
- What is printed? python def isanagram(a, b): return sorted(a) == sorted(b) print(isanagram('listen', 'silent'), isanagram('abc', 'abcc')…
- What is printed? python print(pow(3, 1018, 7), pow(3, 6, 7), pow(3, 1018 % 6, 7))