ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
print(round(2.5), round(3.5), round(-0.5), round(2.675, 2), round(1.005, 2))
- A. 2 4 -1 2.67 1.0
- B. 2 4 0 2.67 1.0
- C. 2 4 0 2.68 1.01
- D. 3 4 0 2.67 1.0
Correct answer: B. 2 4 0 2.67 1.0
round uses round-half-to-even, so 2.5 becomes 2 and 3.5 becomes 4, and -0.5 becomes 0. 2.675 and 1.005 are stored just below the halfway point, so they round down to 2.67 and 1.0.
More Python Programming questions
- What is printed? python a = float('nan') b = float('nan') print(a == a, a is a, a == b, [a] == [a], [b] == [a])
- What is printed? python print(253 + 1 == 253 + 1.0, 253 + 1 == 253, float(253 + 1) == 253)
- What is printed? python pairs = [(2, 'b'), (1, 'z'), (2, 'a'), (1, 'y')] print(sorted(pairs, key=lambda t: t[0])) print(sorted(pairs…
- What is printed on the second line? python words = ['pear', 'fig', 'apple', 'kiwi', 'date'] print(sorted(words, key=lambda w: (-len(w)…
- What is printed? python print(('ab' 3).count('aba'), 'ababa'.count('aba'), 'aaaa'.count('aa'))
- What is printed on the third line? python print('a,b,,c'.split(',')) print(' a b '.split()) print(' a b '.split(' '))