ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(7.5 // 2, 7.5 % 2, -7.5 // 2, divmod(7.5, -2))
- A. 3.0 1.5 -4.0 (-4.0, -0.5)
- B. 3.0 1.5 -3.0 (-3.0, 1.5)
- C. 3.0 1.5 -4.0 (-3.0, -0.5)
- D. 3 1.5 -4 (-4.0, -0.5)
Correct answer: A. 3.0 1.5 -4.0 (-4.0, -0.5)
Float floor division and modulo follow the same sign rules as ints, and the results are floats. divmod(7.5, -2) gives quotient -4.0 and remainder -0.5, since -4.0 * -2 + -0.5 = 7.5.
More Python Programming questions
- What is printed? python print(max([('x', 5), ('y', 5)], key=lambda t: t[1]), min([('x', 5), ('y', 5)], key=lambda t: t[1]))
- What is printed? python print(sorted([1.0, True, 1, 0.5, False]))
- What is printed? python try: print(int('10')) except ValueError: print('bad')
- What is printed? python print(float('1e400'), -float('1e400'), float('1e308') 10)
- What is printed? python print(int(1e23))
- What is printed? python print('x' 0 == '', 'Z' < 'a', '10' < '9', 'apple' < 'Apple')