ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
from fractions import Fraction
print(Fraction(1, 2) + 0.5 == 1, Fraction(1, 3) * 3 == 1, type(Fraction(1, 2) + 1).__name__, type(Fraction(1, 2) + 0.5).__name__)
  1. A. True False Fraction float
  2. B. True True float float
  3. C. True True Fraction float
  4. D. True True Fraction Fraction

Correct answer: C. True True Fraction float

Fraction arithmetic is exact, so the second check is True. Adding an int keeps the result a Fraction, but adding a float converts the result to float.

More Python Programming questions

Exams that ask this topic