ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
print(10 / 4, 10 // 4, -10 // 4, 10 % -4, 2 ** -2, 7 // 2.0)
- A. 2.5 2 -2 2 0.25 3.0
- B. 2.5 2 -3 2 0.25 3
- C. 2 2 -3 -2 0.25 3.0
- D. 2.5 2 -3 -2 0.25 3.0
Correct answer: D. 2.5 2 -3 -2 0.25 3.0
/ always gives a float; // floors (so -10 // 4 = -3); % takes the divisor's sign (10 % -4 = -2); a negative exponent gives a float; // with a float operand returns a float.
More Python Programming questions
- What is printed? python s = "abcdefghij" print(s[2:8:3], s[-2:-9:-3], s[8:2:3] == "", s[::4] + s[1::4])
- What is printed? python L = list(range(10)) L[2:8:2] = "XYZ" del L[-3:] L[len(L):] = [99] print(L)
- What is printed? python d = {"b": 2, "a": 1} print(sorted(d.items()), sorted(d, key=d.get), list(reversed(sorted(d.values()))), {d, "a"…
- What is printed? python from collections import Counter c = Counter(a=3, b=1) c.update("aab") c.subtract({"b": 5}) print(c["a"], c["b"]…
- What is printed? python from collections import ChainMap defaults = {"color": "red", "size": 1} user = {"size": 3} cm = ChainMap(user…
- What is printed? python import bisect grades = "FDCBA" cut = [60, 70, 80, 90] print([grades[bisect.bisect(cut, s)] for s in [59, 60, 85…