ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(7 % 0.5, 7.25 % 0.5, -1 % 0.25)
  1. A. 0.0 0.25 0.0
  2. B. 0.5 0.25 0.0
  3. C. 0.0 0.25 0.5
  4. D. 0.0 0.75 0.0

Correct answer: A. 0.0 0.25 0.0

0.5 and 0.25 are exact binary fractions, so the float remainders are exact. The remainder of -1 by 0.25 is 0.0 because -1 is a multiple of 0.25.

More Python Programming questions

Exams that ask this topic