ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(0.1 + 0.2 > 0.3, 0.5 + 0.25 == 0.75, 1 / 3 * 3 == 1.0)
- A. True True False
- B. True True True
- C. False True True
- D. True False True
Correct answer: B. True True True
0.1 + 0.2 is slightly greater than 0.3 in floating point. 0.5 and 0.25 are exact in binary, so their sum is exact. 1/3 rounds down, but times 3 it rounds back to exactly 1.0.
More Python Programming questions
- What is printed? python words = ['pear', 'fig', 'banana'] index = {w: i for i, w in enumerate(words)} print(index['fig']…
- What is printed? python s = {1, 2, 3} t = s t |= {4} u = s | {5} print(len(s), len(u), t is s)
- What is printed? python def gen(): x = yield 1 print('got', x) yield 2 g = gen() print(next(g)) print(g.send('hi'))
- What is printed? python print(sum(1 for c in 'Mississippi' if c in 'aeiou'), 'Mississippi'.count('ss'), 'Mississippi'.rfind('ss'))
- What is printed? python from math import prod print(prod([]), prod([2, 3, 4]), prod([1.5, 2]))
- What is printed? python print(list(range(10, 0, -3)), list(range(0, -7, -2)), len(range(5, 5)), range(3)[1:])