ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(7 % 0.5, 7.25 % 0.5, -1 % 0.25)
- A. 0.0 0.25 0.0
- B. 0.5 0.25 0.0
- C. 0.0 0.25 0.5
- 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
- What is printed? python print(1 == 1.0 == True, 2 == 2.0 != 3.0)
- What is printed? python print(3 -2 9, (3 -2) 9 == 1.0, 3 -2 9 == 1)
- What is printed? python print(1000000 1000000 == 1012, 106 2 == 1012, 23 2 == 64)
- What is printed? python print(7 & -7, 7 | -7, 7 ^ -7, ~7 & 0xF)
- What is printed? python print(bin(5 & -5), (5).bitcount(), (-5).bitcount(), (-5).bitlength())
- What is printed? python print(0b1 << 100 > 299, (1 << 100).bitlength(), len(bin(1 << 100)) - 2)