ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
print(str(1e21), str(1e15), str(123456789.123), 1e21 == 10**21, float(10**21) == 1e21)
- A. 1e21 1000000000000000.0 123456789.123 True True
- B. 1e+21 1000000000000000.0 123456789.123 False True
- C. 1e+21 1000000000000000.0 123456789.123 True True
- D. 1e+21 1e+15 123456789.123 True True
Correct answer: C. 1e+21 1000000000000000.0 123456789.123 True True
str of a float switches to exponent form at 1e16, so 1e15 prints in full with a .0 suffix. 10**21 is exactly representable as a double, so both equality tests are True.
More Python Programming questions
- What is printed? python print(str(1e-5), 0.0001, 0.00001, 1e-4 == 0.0001, 10 -4)
- What is printed? python print(sorted(['10', '9', '2b', '2a']), sorted([10, 9, 2], key=str))
- What is printed on the last line? python try: sorted([1, '2']) except TypeError: print('TypeError') print(sorted([1, '2'], key=str))
- What is printed? python print(max([], default=-1), min([3], default=0), sum([]), sum([], 0.0), any([]) or all([]))
- What is printed on the first line? python words = ['apple', 'Bob', 'cat', 'Dog', 'ant'] print(sorted(words, key=lambda w: (w[0].lower()…
- What is printed on the second line? python nums = [5, -3, 0, 2, -3] print(sorted(nums, key=lambda x: x < 0)) print(sorted(nums, key=lambda…