sds2019
sds2019 copied to clipboard
Problem 0.3.1 - Writing average function
Hi! I'm getting this problem while doing the problem 0.3.1. I tried different ways to store the result of the average function into answer_031, the output of the following returns 5.0 so I converted to int but I still can't figure it out what I'm missing...
# answer_031 =
l = [1,2,3,4,5,6,7,8,9]
def average(l):
return sum(l) / len(l)
answer_031 = average(l)
print(answer_031)
int(answer_031)
The int()
function returns an integer value but does not modify the parameter passed to it i.e. int(answer_031)
returns the integer value of answer_031
, but leaves the variable unchanged.
In order to assign the integer value to the variable (this means actually using the return value of int( )
) you would have to run:
answer_031 = int(answer_031)
With that said 5 == 5.0
actually evaluates to True
, so there is really no need to convert the variable :)