ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(int(1e23), int(1e20))
- A. 100000000000000000000000 100000000000000000001
- B. 99999999999999991611392 100000000000000000000
- C. 100000000000000000000000 100000000000000000000
- D. 99999999999999999999999 100000000000000000000
Correct answer: B. 99999999999999991611392 100000000000000000000
1e23 cannot be stored exactly as a double, and the nearest double is 99999999999999991611392. 1e20 is exactly representable, so int(1e20) keeps all its digits.
More Python Programming questions
- What is printed? python x = [3, 1, 2].sort() print(x, sorted([3, 1, 2]))
- What is printed? python print(min([(1, 'b'), (1, 'a')], key=lambda t: t[0]), max(['aa', 'b', 'cc'], key=len))
- What is printed? python d = dict.fromkeys(['a', 'b'], []) d['a'].append(1) print(d)
- What is printed? python list = [1] try: print(list(range(2))) except TypeError as e: print(e)
- What is printed? python import heapq g = {'A': [('B', 1), ('C', 4)], 'B': [('C', 2), ('D', 5)], 'C': [('D', 1)], 'D': []} dist = {k…
- What is printed? python print(pow(10, 100, 7), pow(2, 10, 1000), pow(7, 0, 7))