Question discussion

What is the output of the following Python code?print(round(2.5), round(3.5), round(0.5), round(1.5), round(2.675, 2))

1770Medium DSSSB TGT Computer Science 0 replies

What is the output of the following Python code?

print(round(2.5), round(3.5), round(0.5), round(1.5), round(2.675, 2))
  • A3 4 1 2 2.68
  • B2 4 0 2 2.67
  • C2 4 1 2 2.68
  • D3 4 0 2 2.67
Correct answer: B

Explanation

Python 3 rounds halves to the nearest even integer (2, 4, 0, 2), and 2.675 is stored slightly below 2.675, so round(2.675, 2) gives 2.67.

Discussion 0

Nobody has replied yet. Start the discussion!