ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(0.1 + 0.2 > 0.3, 0.3 - 0.1 == 0.2, 0.2 + 0.2 == 0.4, 0.4 - 0.2 == 0.2)
- A. True False True True
- B. False False True True
- C. True True True True
- D. True False False True
Correct answer: A. True False True True
0.1 + 0.2 is slightly above 0.3. 0.3 - 0.1 is 0.19999999999999998, while doubling 0.2 and subtracting 0.2 from 0.4 both land exactly on the nearest doubles.
More Python Programming questions
- What is printed? python from collections import defaultdict d = defaultdict(int) for w in 'a b a c'.split(): d[w] += 1…
- What is printed? python print(sum([1e100, 1.0, -1e100]) == 1.0, sum([1, 1e100, -1e100]), 1e100 + 1.0 - 1e100)
- 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…