ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
y = 1 + 1 - 1 * 2 ** 2 // 4 print(y, 2 ** 2 ** 0, (2 ** 2) ** 0, -3 ** 2 % 5)
- A. 1 4 1 1
- B. 2 2 1 1
- C. 1 2 1 1
- D. 1 2 1 4
Correct answer: C. 1 2 1 1
** is right-associative, so 2 ** 2 ** 0 is 2 ** 1 = 2, and any number to the power 0 is 1. Unary minus binds looser than **, so -3 ** 2 is -9, and -9 % 5 is 1.
More Python Programming questions
- 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))
- What is printed? python print('%s and %s' % ('A', 'B'), '%(x)d-%(x)05.1f' % {'x': 3}, '%%%d' % 5)
- What is printed? python print(1 / 2 + 1 // 2 + 1 % 2, 1 / 2 2 == 1, 3 1 / 2 == 3 (1 / 2))
- What is printed? python print(0x10 + 0o10 + 0b10, 10 + 0x1, 1e1 + 1, 1j 1j)