ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
from fractions import Fraction
print(Fraction(1, 3) + Fraction(1, 6), Fraction(0.5), Fraction('0.1') + Fraction(0.1) == Fraction(1, 5), Fraction(3, -6))- A. 1/2 1/2 True -1/2
- B. 1/2 1/2 False 1/3
- C. 1/2 1/2 False -1/2
- D. 1/2 3/2 False -1/2
Correct answer: C. 1/2 1/2 False -1/2
Fraction(0.1) is built from the exact binary value of the float, which is not exactly 1/10, so the sum is not 1/5. A negative denominator moves the sign to the numerator, giving -1/2.
More Python Programming questions
- What is printed? python print(int('0b101', 0), int('0o17', 8), int('z', 36), int('-0'), int('+7'))
- What is printed? python print(str(True) + str(1 == 1.0), True + True, '3' True, [0] True)
- What is printed? python print(max('apple', 'banana', key=len), max('pear', 'fig', key=len), min('bb', 'aa', 'c', key=len))
- What is printed? python print('ab'.startswith(('x', 'a')), 'abc'.endswith('', 3), 'abc'.index('c', -1), 'aXbX'.split('X', 1))
- What is printed? python print(ord('A') + 1, chr(ord('a') + 25), chr(0x1F600) == 'U0001F600', len('U0001F600'), 'N{SNOWMAN}')
- What is printed? python from functools import cmptokey w = ['bb', 'a', 'ccc', 'ab', 'c'] def c(x, y): if len(x) != len(y): return len(x)…