ProgrammingVery hardJEE Main · CAT placement
What is printed?
What is printed?
print(10**20 + 1 - 10**20, float(10**20 + 1) - float(10**20))
- A. 1 1.0
- B. 1 0.0
- C. 0 0.0
- D. 1 16384.0
Correct answer: B. 1 0.0
Python ints are exact, so the first difference is 1. 10**20 + 1 needs more than 53 bits, so float() rounds it back to 10**20, and the float difference is 0.0.
More Python Programming questions
- What is printed? python data = [('b', 2), ('a', 2), ('c', 1), ('a', 1)] print(sorted(sorted(data, key=lambda t: t[0]), key=lambda t: t[1]…
- What is printed? python print(int('0x1F', 16), int('1F', 16), int('0b101', 0), int(' 42 '), int('42'))
- What is printed? python print(int('٣') + 1)
- What is printed? python print(bin(10)[2:].zfill(8), format(-10, '08b'), format(-10 & 0xFF, '08b'), f'{255:#x}')
- What is printed? python print((1 << 70).bitcount(), (270 - 1).bitcount(), (-1).bitcount(), (-8).bitcount())
- What is printed? python print(f'{0.1:.20f}', f'{1e16:g}', f'{123456789.0:e}', f'{2.5:.0f}', f'{3.5:.0f}')