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))
  1. A. 1/2 3/4 3/4 1/3
  2. B. 1/2 3/4 1/4 1/2
  3. C. 1/2 3/4 3/4 1/2
  4. 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

Exams that ask this topic