ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(float('0.1') == 0.1, float(' 0.1 ') == 0.1, 0.1 == float(str(0.1)), 1e23 == 10**23)- A. True True False True
- B. False True True False
- C. True False True False
- D. True True True False
Correct answer: D. True True True False
float() parses the decimal text to the same nearest double as the literal, so the first three comparisons are True. The float 1e23 is not exactly 10**23, so the exact int comparison is False.
More Python Programming questions
- What is printed? python total = 0 for s in ['10', '9', ' x', '+7', '10']: try: total += int(s) except ValueError: total -= 1 print(total)
- What is printed? python print('%d' % 3.9, '%d' % -3.9, '%.0f' % 0.5, '%i' % True)
- What is printed? python s = 'héllo' print(s[1], s.encode('latin-1')[1], len(s.encode('utf-16-le')), s.isascii())
- What is printed? python from decimal import Decimal, getcontext getcontext().prec = 4 print(Decimal(1) / Decimal(3), Decimal('1.10') ==…
- What is printed? python print(sorted([(2, 'b'), (1, 'z'), (2, 'a')], reverse=True))
- What is printed? python print(7 / 2 // 1, 7 // 2 / 1, -7 / 2 // 1, 7 % 2.5)