sds2019 icon indicating copy to clipboard operation
sds2019 copied to clipboard

Problem 0.3.1 - Writing average function

Open GuidoTurdera opened this issue 5 years ago • 1 comments

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)

GuidoTurdera avatar Aug 03 '19 12:08 GuidoTurdera

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 :)

sebastianbaltser avatar Aug 03 '19 14:08 sebastianbaltser