ProgrammingVery hardCAT · MBA placement
What is printed?
What is printed?
print(round(0.5), round(1.5), round(2.5), round(-0.5), round(2.675, 2))
- A. 0 2 2 0 2.67
- B. 0 2 2 0 2.66
- C. 1 2 3 -1 2.68
- D. 0 1 2 0 2.68
Correct answer: A. 0 2 2 0 2.67
round with no digits uses round-half-to-even, so 0.5 goes to 0 and 2.5 goes to 2. round(2.675, 2) prints 2.67 because 2.675 is stored slightly below its decimal value.
More Python Programming questions
- What is printed? python s = 'aaaa' print(s.count('aa'), s.replace('aa', 'b'), 'a,,b'.split(','), ' x y '.split(' '))
- What is printed? python import itertools print([''.join(p) for p in itertools.permutations('abc', 2)][:4])
- What is printed? python import itertools print(len(list(itertools.combinationswithreplacement(range(5), 3))))
- What is printed? python import itertools print(sum(1 for t in itertools.product('01', repeat=10) if t.count('1') == 3))
- What is printed? python import itertools g = itertools.groupby('aab') k, grp = next(g) next(g) print(k, list(grp))
- What is printed? python import itertools g = iter(range(10)) print(list(itertools.islice(g, 2, 7, 2)), next(g))