How is this not the first option?


After testing the code, only the first option was correct after running in Jupyter. Removing the average = 0 produced the correct answer but wasn’t the correct option. Once the 3rd option was unindented, the answer became 85.445583765504

Jupyter can be tricky if you’re not careful as the ipykernel it’s running on will maintains state. I think in this case you’re mixing up multiple different examples, so after running the code once it actually saves average. If you removed the average = 0 when your calculation might not be starting from 0. Try restarting your kernel to clear any hidden states (if you have other useful work in that session then consider running this snippet elsewhere). Or, easier still just add that average = 0 back into your code so you know exactly what value average refers to.

4 Likes

Thank you for the tip @tgrtim. :smiley: I restarted the kernel after unindenting the average = average / len(grades) and it produced the correct result :
image

I’m still new to using Jupyter and am so used to changing one line and it fixes itself when I run it. :sweat_smile:

Again, thank you for the quick reply.

1 Like

Hehe, it’s all good. I don’t think there’s anyone around who’s used a notebook who has not been bitten at least once by hidden state variables :sweat_smile:. At least it teaches you about the benefits of proper initialisation or something.