ProgrammingVery hardJEE Advanced · CAT placement
What is printed?
What is printed?
print(sum([1e100, 1.0, -1e100]) == 1.0, sum([1, 1e100, -1e100]), 1e100 + 1.0 - 1e100)
- A. False 0 0.0
- B. True 0.0 0.0
- C. True 1.0 0.0
- D. False 1.0 0.0
Correct answer: B. True 0.0 0.0
Plain left-to-right addition loses the 1.0 next to 1e100. Since Python 3.12, sum() of floats compensates for rounding, so sum([1e100, 1.0, -1e100]) keeps 1.0. But the integer 1 is absorbed when it is added before the first float, so sum([1, 1e100, -1e100]) is 0.0.
More Python Programming questions
- What is printed on the third line? python emp = [('Ravi', 30, 'IT'), ('Asha', 25, 'HR'), ('Meera', 30, 'HR'), ('Dev', 25, 'IT')] byage =…
- What is printed on the second line? python items = [3, -1, 2, -3, 1] print(sorted(items, key=abs)) print(sorted(items, key=abs…
- What is printed on the second line? python data = [('b', 2), ('a', 2), ('c', 1), ('a', 1)] print(sorted(data, key=lambda t: (t[1], t[0])…
- What is printed on the second line? python words = ['bb', 'a', 'ccc', 'dd', 'e'] print(sorted(words, key=len)) print(sorted(words…
- What is printed on the last line? python nums = ['10', '9', '100', '1'] print(sorted(nums)) print(sorted(nums, key=int)) print(max(nums)…
- What is printed on the third line? python print(sorted([(1, 'x'), (1, 'X'), (0, 'z')], key=lambda t: t[1].lower())) print(sorted(['b'…