ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(sum(i * (-1) ** i for i in range(1, 7)), (-1) ** 7 + 0.0, (-1.0) ** 2, (-2) ** -2)
- A. 3 -1.0 1.0 0.25
- B. 3 -1.0 1.0 0.5
- C. 2 -1.0 1.0 0.25
- D. 3 -1.0 2.0 0.25
Correct answer: A. 3 -1.0 1.0 0.25
The alternating sum is -1 + 2 - 3 + 4 - 5 + 6 = 3. Negative int exponents give floats, so (-2) ** -2 is 0.25.
More Python Programming questions
- What is printed? python def f(n): return sum(d if n % 2 else -d for d in range(1, n + 1)) print(f(1), f(2), f(3), f(4))
- What is printed? python print(int('-0b11', 0), int('01', 0) if False else 0, int('1000'), int(' 0010 '))
- What is printed? python print(abs(-263) == 263, abs(-0.0) == 0.0, abs(-2.5) // 1, -2.5 // 1 -1)
- What is printed on the second line? python import math print(math.gcd(12, 18, 24), math.gcd(), math.lcm(), math.lcm(4, 0, 9))…
- Which line is printed? python print(divmod(270, 106)[1] == 270 % 106, divmod(-270, 106)[1] == (-270) % 106, (-270) // 106 == -(270 // 106)…
- What is printed? python from collections import Counter print(Counter('mississippi').mostcommon(3))