ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
print(7 // -2, -7 // 2, 7.0 // -2, -7.0 % 2)
- A. -3 -4 -3.0 1.0
- B. -4 -4 -4.0 2.0
- C. -4 -3 -4.0 1.0
- D. -4 -4 -4.0 1.0
Correct answer: D. -4 -4 -4.0 1.0
Both // and % use floor semantics in Python: the quotient rounds toward minus infinity, and the remainder takes the sign of the divisor, so -7.0 % 2 is 1.0.
More Python Programming questions
- What is printed? python print(abs(-0.0), -0.0 == 0.0, str(-0.0), str(-0.0 + 0.0))
- What is printed? python print(sum([0.1] 10) == 1.0, sum([0.1] 10), sum([0.1] 10, 0) == 1.0)
- What is printed? python print(int(3.9999999999999999), int(-3.7), round(-3.7))
- What is printed? python print(hash(1) == hash(1.0), hash(True) == 1, {1: 'a', 1.0: 'b', True: 'c'})
- What is printed? python print(0.1 3 == 0.3, 0.1 3, 0.3 3 == 0.9)
- What is printed? python inf = float('inf') print(inf > 10400, inf - inf == 0, -inf < -10400, inf == inf)