ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
n = 12 print(n & 1 == 0, (n & 1) == 0, n & n - 1 == 0, 8 & 7 == 0)
- A. True True False True
- B. False True False True
- C. True True True True
- D. True True False False
Correct answer: A. True True False True
In Python & binds tighter than ==, so n & 1 == 0 means (n & 1) == 0, which is True for 12. n & (n - 1) is 8 for 12, so the power-of-two test fails, while 8 & 7 is 0.
More Python Programming questions
- What is printed on the first line? python print(pow(2, -1, 5), pow(3, -1, 7), pow(2, -3, 9)) try: print(pow(2, -1, 4)) except ValueError…
- What is printed? python import math print(math.comb(100, 50) % 1000, len(str(math.comb(100, 50))), math.perm(5, 2), math.comb(5, 7))
- What is printed? python import math print(math.floor(-0.5), math.ceil(-0.5), math.trunc(-0.5), math.floor(2.999999999999999999))
- What is printed? python print(f'{1234567.891:.2f}', f'{255:#x}', f'{5:03d}', f'{-5:03d}', f'{-5:+04d}')
- What is printed? python print(str(-0), int('-0'), -0.0 == 0, str(-0.0), 0 -1.0)
- What is printed? python print(str(1e21), str(1e15), str(123456789.123), 1e21 == 1021, float(1021) == 1e21)