ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
print(7 // 2 * 2, 7 / 2 * 2, 2 ** 3 ** 2)
- A. 6 7.0 64
- B. 6 7 512
- C. 6 7.0 512
- D. 8 7.0 512
Correct answer: C. 6 7.0 512
// and * have the same precedence and run left to right, so 7 // 2 * 2 is 6. / always gives a float, and ** is right-associative, so 2 ** 3 ** 2 is 2 ** 9.
More Python Programming questions
- What is printed? python print([1, 2] < [1, 3], [1, 2] < [1], 'b' > 'abc')
- What is printed? python print(isinstance([], list) and isinstance((), tuple), type([]) == list)
- What is printed? python print(''.join(sorted('hello', key=lambda c: c in 'aeiou')))
- What is printed? python print(len({(1, 2): 'a', (2, 1): 'b', (1, 2): 'c'}))
- What is printed? python x = 5 def f(): return x x = 6 print(f(), (lambda: x)())
- What is printed? python print(list(range(10))[2:8:3], list(range(10))[::4])