ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
print(7 // 1.0 * 1, 1e3 // 7, -1e3 // 7, 10 % -3.0)
- A. 7 142.0 -143.0 -2.0
- B. 7.0 142.0 -142.0 -2.0
- C. 7.0 142.0 -143.0 -1.0
- D. 7.0 142.0 -143.0 -2.0
Correct answer: D. 7.0 142.0 -143.0 -2.0
Any float operand makes // and % return floats. 1000 // 7 is 142.0, while -1000 // 7 floors to -143.0. A negative divisor gives the remainder a negative sign, so 10 % -3.0 is -2.0.
More Python Programming questions
- What is printed? python print(bool(''), bool('False'), bool([]), bool([[]]), bool(None))
- What is printed? python print(str(3) + str(3.0), 3 + 3.0, '3' 3 == '333')
- What is printed? python y = 1 + 1 - 1 2 2 // 4 print(y, 2 2 0, (2 2) 0, -3 2 % 5)
- What is printed? python t = 'racecar' print(t == t[::-1], t.find('car'), t.rfind('c'), t.replace('car', 'CAR', 1))
- What is printed? python s = 'one two three' print(s.split(' '), len(s.split()), s.split(None, 1)[1], '-'.join(s.split()))
- What is printed? python print('ab'.ljust(4, '') + '|', 'ab'.rjust(4, ''), 'ab'.zfill(4), '12'.zfill(1))