ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(round(2.5), round(3.5), round(-0.5), int(-2.7), -7 // 2, -7 % 2)
- A. 3 4 -1 -3 -3 -1
- B. 2 4 0 -2 -4 1
- C. 3 4 0 -2 -4 1
- D. 2 4 0 -3 -4 1
Correct answer: B. 2 4 0 -2 -4 1
Python rounds halves to the nearest even number (banker's rounding): 2, 4 and 0 (shown as 0, not -0). int() truncates toward zero (−2). // floors (−4) and % takes the divisor's sign (1), so (−7 // 2)·2 + (−7 % 2) = −7.
More Python Programming questions
- What is printed? python from collections import Counter c = Counter("mississippi") print(c.mostcommon(2), c["z"], sum(c.values()))
- What is printed? python a, b, c = range(6) x, y = y, x = 1, 2 print(a, b, c, x, y)
- What is printed? python words = ["banana", "Apple", "cherry", "apple"] print(sorted(words), sorted(words, key=str.lower)[:2], max(words…
- What is printed? python i = 10 squares = [i i for i in range(3)] for j in range(3): pass print(i, squares, j)
- What is printed? python s = " Hello, World " print(s.strip().lower().split(","), s.count("l"), s.find("z"), "-".join("abc"))
- What is printed? python def f(args, kw): return len(args), sorted(kw) print(f(1, 2, [3, 4], a=5, {"b": 6}))