ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(int(-7 / 2), -7 // 2, int(7 / -2), 7 // -2)
- A. -3 -4 -3 -3
- B. -3 -3 -3 -4
- C. -4 -4 -3 -4
- D. -3 -4 -3 -4
Correct answer: D. -3 -4 -3 -4
int() truncates toward zero, while // floors toward minus infinity, so -7 / 2 gives -3 under int but -4 under //. The same split happens for 7 / -2.
More Python Programming questions
- What is printed? python print(7 % 0.5, 7.25 % 0.5, -1 % 0.25)
- 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())