ProgrammingVery hardCAT · MBA placement
What is printed?
What is printed?
from fractions import Fraction
print(Fraction(3, 6), Fraction('0.75'), Fraction(0.75), Fraction(1, 3) + Fraction(1, 6))- A. 1/2 3/4 3/4 1/3
- B. 1/2 3/4 1/4 1/2
- C. 1/2 3/4 3/4 1/2
- D. 1/2 3/4 3/4 2/3
Correct answer: C. 1/2 3/4 3/4 1/2
Fraction reduces to lowest terms, so 3/6 is 1/2. 0.75 is exactly 3/4 in binary, so both the string and float forms give 3/4. 1/3 + 1/6 is 1/2.
More Python Programming questions
- What is printed? python print(divmod(7, 2.5), divmod(-7.5, 2))
- What is printed? python print(0.1 + 0.1 + 0.1 == 0.3, 0.1 + 0.1 + 0.1, 0.3 == 3 0.1)
- What is printed? python print(bin(5 ^ 3), bin(-5 & 0b1111), int('-0b101', 2))
- What is printed? python print(2 -1, 2 -1074 > 0, 10 -3 == 0.001, 10 -2)
- What is printed? python print(' '.join(['a', '', 'b']), ' '.join([]) == '', '-'.join('abc'), 'x'.join(['1', '2', '3']))
- What is printed? python from functools import reduce print(reduce(lambda a, b: a + b, ['x', 'y', 'z'], ''), reduce(lambda a, b: a b…