ProgrammingVery hardJEE Advanced · CAT placement
What is printed?
What is printed?
from fractions import Fraction
print(Fraction(1, 3) == 1/3, Fraction(1, 3) == Fraction('0.3333333333333333'), float(Fraction(2, 3)) == 2/3, Fraction(0.1) == 0.1)- A. True False True True
- B. False True True True
- C. False False True True
- D. False False False True
Correct answer: C. False False True True
Comparing a Fraction with a float is exact, and 1/3 is not a float, so the first two comparisons are False. Fraction(0.1) is the exact binary value of the float, so it equals 0.1.
More Python Programming questions
- What is printed? python print('Hello, World'.swapcase(), 'hello world'.title(), "it's here".capitalize(), 'ABC'.isupper())
- What is printed? python print(float('9007199254740993') == 9007199254740993, int(float('9007199254740993')), int(9007199254740993.0))
- What is printed? python print(len('abc' 1000000 + ''), 'abc' in 'x' 10 + 'abc', 'ab' < 'abc', [1, 2] < [1, 2, 0])
- What is printed? python print(10 -1 == 0.1, 10 0.5 == 10 (1 / 2), int(10 0.5) 2 == 10, round(10 0.5 10 0.5, 9))
- What is printed? python from functools import cmptokey print(sorted(['10', '9', '2'], key=cmptokey(lambda a, b: int(a) - int(b))))
- What is printed? python print(1 << 31 >> 31, (1 << 31) >> 31 == 1, -1 >> 31, -231 >> 31)