PYTHON round Forthis problem,we'll round an int value up to the next multiple of 10 ifits rightmost digit is 5 or more,so 15 rounds up to 20.Alternately,round down to the previous multiple of 10 if its rightmost digit is lessthan 5,so 12 rounds down
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/23 19:29:44
PYTHON round Forthis problem,we'll round an int value up to the next multiple of 10 ifits rightmost digit is 5 or more,so 15 rounds up to 20.Alternately,round down to the previous multiple of 10 if its rightmost digit is lessthan 5,so 12 rounds down
PYTHON round
For
this problem,we'll round an int value up to the next multiple of 10 if
its rightmost digit is 5 or more,so 15 rounds up to 20.Alternately,
round down to the previous multiple of 10 if its rightmost digit is less
than 5,so 12 rounds down to 10.Given 3 ints,a b c,return the sum of
their rounded values.To avoid code repetition,write a separate helper
"def round10(num):" and call it 3 times.
Example Output:round_sum(16,17,18) → 60round_sum(12,13,14) → 30round_sum(6,4,4) → 10
PYTHON round Forthis problem,we'll round an int value up to the next multiple of 10 ifits rightmost digit is 5 or more,so 15 rounds up to 20.Alternately,round down to the previous multiple of 10 if its rightmost digit is lessthan 5,so 12 rounds down
$ python
Python 2.7.3 (default, Jan 2 2013, 16:53:07)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def round_sum(*args):
... return sum(map(lambda x: round(x, -1), args))
...
>>> round_sum(16, 17, 18)
60.0
>>> round_sum(12, 13, 14)
30.0
>>> round_sum(6, 4, 4)
10.0
>>>