Seeking help with Module 4 Ex3 candies assignment

Hello, I am stuck on Exercise 3 in the candies assignment in the week 4 module.

Two issues:

“Use the mean function from your stats module (remember how to use an alias with the dot . ) to find the average popularity score of all the candies.” ←- I have no recollection of how to do this and am not seeing it in the lecture notes. Could somebody point me to the right format/location in the lesson?

-I am getting the attached error after successfully importing the stats package; any ideas on how to troubleshoot? Thanks!

Screenshot 2026-03-17 at 1.58.38 PM

I’m not a mentor for this course. But in general, the way you could call the “mean()” method of a “stats” object would be:

stats.mean(…)

In order for the “stats” module to exist, you must be sure you have run the cell that creates it.

So in general, every time you open a notebook, you should run all of the cells starting from the top. That’s how the workspace is created.

1 Like

Thank you! I think the stats.mean function is now working, but I’m still getting the error “No module named ‘stats’” even after rerunning all of the cells. Any other suggestions?

Sorry, but that statement has confused me.

If you say the function is working, then how can you also get a no module named ‘stats’ error message?

There were two issues - one was that I couldn’t remember the alias function (which your suggestion addressed), the other was that the code doesn’t seem to recognize the stats module I imported. The latter has not been fixed after I reran the code.

Sorry, I haven’t attended this course myself. I’m not a mentor for it.

Does the assignment already import the stats function, or did you add that yourself?

Or in other words, are you supposed to use the ‘stats’ module for this assignment?

can post screenshot of the complete error @ellbee

No problem - I appreciate your engagement on it! Here are the instructions:

Import the Python package statistics as stats

(^I did this and tests passed)

Then, the next instruction was: Time to calculate! Use the mean function from your stats module (remember how to use an alias with the dot . ) to find the average popularity score of all the candies.

And received this error:

Yes, thank you - just posted it in reply to @TMosh

You don’t need from stats import mean. The instructions didn’t ask you to do that.

The syntax it asked you to use was:
import statistics as stats

After that, then you can use stats.mean(...)

1 Like

OK, I figured it out! Thank you!

1 Like

Nice work!

1 Like

Great @ellbee
Always! post screenshot of complete error, so that it helps mentors to understand why you encountered the error even if they haven’t done the course, some mentors can find the reason behind error when we have a complete log of the error or atleast provide steps to resolve your issue.

regards
Dr. Deepti

1 Like