ProgrammingVery hardWipro · Accenture · Capgemini pattern
What does the following Python 3 code print? print(2 ** 10, 2 ** 0.5, 10 // 3, -10 // 3, 10 % 3, -10 % 3)
- A. 1024 1.41 3 -3 1 -1
- B. 1024 1.4142135623730951 3 -4 1 -2
- C. 1024 1.4142135623730951 3 -4 1 2
- D. 1024 1.4142135623730951 3 -3 1 1
Correct answer: C. 1024 1.4142135623730951 3 -4 1 2
Floor division rounds toward negative infinity, so -10//3 is -4 (not -3); the modulo result always takes the sign of the divisor, so -10 % 3 is 2.
More Python Programming questions
- What does the following Python 3 code print? print(id([1, 2]) == id([1, 2]))
- What does the following Python 3 code print? try: a = (1, 2, 3) a[0] = 9 except TypeError: print("TypeError")
- What does the following Python 3 code print? try: d = {} print(d["missing"]) except KeyError: print("KeyError")
- What does the following Python 3 code print? try: s = "abc" print(s[10]) except IndexError: print("IndexError")
- What does the following Python 3 code print? try: x = int("12a") except ValueError: print("ValueError")
- What does the following Python 3 code print? try: def f(a, b): return a + b f(1) except TypeError: print("TypeError")