ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(1 / 3 + 1 / 3 + 1 / 3 == 1.0, 0.1 + 0.7)
- A. False 0.8
- B. True 0.7999999999999999
- C. False 0.7999999999999999
- D. True 0.8
Correct answer: B. True 0.7999999999999999
Three thirds add up to exactly 1.0 in floating point here. 0.1 + 0.7 is 0.7999999999999999 because neither operand is exact.
More Python Programming questions
- What is printed? python print(sorted([(-1, 'b'), (-1, 'a'), (0, 'c')]), max([(1, 'z'), (1, 'a')]))
- What is printed? python x = 0 for i in range(5): x += i if i % 2 else -i print(x)
- What is printed? python it = iter([3, 1, 0, 5, 0]) out = [] for x in iter(lambda: next(it), 0): out.append(x) print(out, list(it))
- What is printed? python s = 'key=value=end' print(s.partition('='), s.rpartition('='), 'a b'.split(' '))
- What is printed? python def shift(s, k): return ''.join(chr((ord(c) - 97 + k) % 26 + 97) if c.islower() else c for c in s)…
- What is printed? python def closest3(a, t): a = sorted(a) best = None for i in range(len(a) - 2): l, r = i + 1, len(a) - 1 while l < r: s…