How to use the built-in round() function

Viewed 127

I am trying to solve ? in the expression below:

round(5.18, ?)

The result should be 10.0.

I have thought of round(5.18, print(10.0)), but that isn't it because that gives:

10.0
5
3 Answers

answer should be 10.0

>>> round(5.8, -1)
10.0

So the python help says:

Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.
    
    The return value is an integer if ndigits is omitted or None.  Otherwise
    the return value has the same type as the number.  ndigits may be negative.

So, set ndigits to -1 digit after the comma

>>> round(5.8, -1)
10.0

Just write it as follows: round(5.8, -1)

and check the documentation for more about the built-in round function.

Related