ProgrammingVery hardGATE CS · Product-company placement
What is printed?
What is printed?
x = 2**53 print(float(x + 1) == x, x + 1.0 == x, (x + 2.0) - x, int(float(x + 3)) - x)
- A. True True 2.0 2
- B. True True 2.0 4
- C. True False 2.0 4
- D. True True 0.0 4
Correct answer: B. True True 2.0 4
Above 2**53 the gap between doubles is 2, so 2**53 + 3 is exactly halfway between two doubles and rounds to the even one, 2**53 + 4. Ints stay exact, but float(x + 3) does not.
More Python Programming questions
- What is printed? python print([10, 20, 30][True], (5).bitlength(), (True).bitlength(), (-1).bitlength())
- What is printed? python print(round(7.5), round(6.5), round(-7.5), round(7.5000001))
- What is printed? python print(-7.5 % 2, 7.5 % -2, -0.0 % 3)
- What is printed? python words = 'the quick brown the lazy the'.split() counts = {} for w in words: counts[w] = counts.get(w, 0) + 1…
- What is printed? python print('%.3f' % 1.0005, '%.1f' % 0.25, '%.1f' % 0.35, round(0.35, 1))
- What is printed? python from collections import Counter c = Counter('mississippi') print(c.mostcommon(2), sorted(c.items(), key=lambda kv…