ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
print(0.1 + 0.2 != 0.3, 1 if 0.1 + 0.2 else 0, 0.0 or -0.0 or 'x', 0 and 1 or 2)
- A. True 1 x 2
- B. False 1 x 2
- C. True 0 x 2
- D. True 1 0 0 2
Correct answer: A. True 1 x 2
0.1 + 0.2 is not equal to 0.3, and any non-zero float is truthy. 0.0 and -0.0 are both falsy, so or returns the next value, and 0 and 1 is 0, so or 2 gives 2.
More Python Programming questions
- What is printed? python print(len('u0301'), len('au0301'), 'au0301'.upper() == 'Au0301')
- What is printed? python words = 'the quick the lazy'.split() counts = {} for w in words: counts[w] = counts.get(w, 0) + 1 print(counts…
- What is printed? python print(sorted(['B', 'a', 'C'], key=str.casefold) == ['a', 'B', 'C'], sorted(['B', 'a', 'C']) == ['B', 'C', 'a']…
- What is printed? python print(int('1000') + int('01'), '1000'.replace('', '') == '1000', float('10.50'), '%.1f' % float('10.50'))
- What is printed? python print(round(-1234.5, -2), round(123456.0, -3), round(0.0, 2), round(1e-7, 7))
- What is printed? python print(str(1.0), str(1), str(1.0e0), str(10.0 0), repr(1e0))