ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
from fractions import Fraction
print(Fraction(7, 3) > 2, float(Fraction(7, 3)), Fraction(7, 3) // 1, Fraction(-7, 3) // 1)
  1. A. True 2.33 2 -2
  2. B. False 2.3333333333333335 2 -3
  3. C. True 2.3333333333333335 2 -3
  4. D. True 2.3333333333333335 3 -3

Correct answer: C. True 2.3333333333333335 2 -3

7/3 is greater than 2, and float() rounds it to the nearest double. Floor division of a Fraction by 1 gives the integer floor, which is 2 here and -3 for -7/3.

More Python Programming questions

Exams that ask this topic