ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(7 % 3 ** 2, (7 % 3) ** 2, -7 % 3 ** 2, 2 * 3 ** 2 % 4)
- A. 7 1 2 4
- B. 1 1 2 2
- C. 7 2 2 2
- D. 7 1 2 2
Correct answer: D. 7 1 2 2
** binds tighter than %, so 7 % 3 ** 2 is 7 % 9 = 7. Parentheses change the result to 1, and -7 % 9 is 2 because the remainder takes the divisor's sign.
More Python Programming questions
- What is printed? python print(len(' a b '.split()), len(' a b '.split(' ')), len('anbn'.splitlines()), len('anbn'.split('n')))
- What is printed? python print(list('abc'.encode()), 'abc'.encode()[0] + 1, bytes('hi', 'ascii') == b'hi')
- What is printed? python x = 17 print(x.bitlength(), (x & -x).bitlength(), x.bitcount(), bin(x)[2:].zfill(8))
- What is printed? python print(int(2.5 4) // 3, int(10 / 4 2), 10 // 4 2, 10 / 4 // 2)
- What is printed? python print(float(1) / 3 + float(2) / 3 == 1.0, 0.1 0.1 100 == 1.0, 1 - 0.1 9 == 0.1)
- What is printed? python print(f"{0.1:.20f}")