How would I round 'com' in this Python code?
def percentage(com,rd):
apl = [10,10,10,5,5,20,10,10,10,10]
if age > 15:
t=sum(apl)
if age < 15:
t=sum(apl) + 10
com=rd/t*100
*round(com,0)*
return com
Pretty fine, except that you have to store the returned value somewhere:
def percentage(rd):
apl = [10,10,10,5,5,20,10,10,10,10]
if age > 15:
t=sum(apl)
if age < 15:
t=sum(apl) + 10
com=rd/t*100 #this overwrites whatever the passed argument com was.
com = round(com,0) #assign the rounded value back to com
return com
Also, you don't actually need com as a parameter, since you assigned it in the function.
Hope this helps!
com = round(com,0)
round
is a function that just returns a value, does not modify the variable you provide it. You have to assign that value yourself.
You probably want the round
function. Say you wanted to round it to the nearest ten:
>>> i = 222
>>> print round(i, -1)
220.0