ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
print((-1) ** 0.5, (-1) ** 2, (-8) ** (1 / 3), -1 ** 0.5)
- A. nan 1 nan -1.0
- B. (6.123233995736766e-17+1j) 1 (-2+0j) -1.0
- C. (6.123233995736766e-17+1j) 1 (1.0000000000000002+1.7320508075688772j) -1.0
- D. 1j 1 (-2+0j) 1.0
Correct answer: C. (6.123233995736766e-17+1j) 1 (1.0000000000000002+1.7320508075688772j) -1.0
In Python 3, a negative base raised to a fractional power returns a complex number, so (-1) ** 0.5 is the principal square root i (with a tiny float error). -1 ** 0.5 parses as -(1 ** 0.5) = -1.0.
More Python Programming questions
- Which three lines are printed? python import sys print(sys.getintmaxstrdigits()) try: int('1' 5000) print('parsed') except ValueError…
- What is printed? python import math print(math.isclose(0.1 + 0.2, 0.3), math.isclose(1e-12, 0), math.isclose(1e-12, 0, abstol=1e-9))
- What is printed? python print(int('١٢٣') + 1, 'ß'.upper(), 'Dž'.lower(), len('ß'.upper()))
- What is printed? python total = 0.0 for in range(10): total += 0.1 print(total, total == 1.0, sum([0.1] 10) == 1.0)
- Which of these is the best way to build a string from n pieces in CPython, and why?
- A program makes 10^5 membership checks of the form x in visited, where visited holds 10^5 items. Which statement is correct?