C1M4_Assignment fails despite all checks passing

I am getting a 0 on my assignment submission. Each exercise has the same error message shown below. I successfully use the get_top_candies function in the Exercise 4. Please help me figure out why this isn’t working!

Hi @James_Phillips ,

You need to run your code from the first code cell and in sequence. Here is what you can do to rerun your code, from the menu bar at the top of your notebook:
Kernel → restart & clear all
Cell → run all

click the Save button before submit your assignment.

1 Like

Thanks, I’ll try that and let you know.

Hi,

Thanks for your help!

I followed your instructions and the error in my code was revealed. What’s interesting is that this code snippet, before I restarted the kernel, produced the correct output even though the syntax was incorrect. How did that happen?

### START CODE HERE ###

# Access the "get_top_candies" function in "ex4_helper_functions"
# Pass "candy_data" and "avg_popularity" to the "get_top_candies" function
top_candies = get_top_candies(candy_data, avg_popularity)

### END CODE HERE ###

### Display the "top_candies" list
ex4_helper_functions.display_pretty_table(top_candies)

When pasting python code in a Discourse post, you need to format it using the “{}” tool or else it gets interpreted as markdown and is not really that readable. I edited your post to show how that is done. But the other thing to consider here is that we aren’t supposed to share solution code in public forum posts. Once @kic has had a chance to look, we should edit it again to remove the source code.

Back to your actual question: sorry, I am not a mentor for this course, but one thing to realize about the Jupyter notebooks is that just typing code in a cell and then calling that function again runs the old code. You have to either click “Shift-Enter” on the actual function cell or do “Cell → Run All” to get the cell to actually execute, which loads your newly modified code.

1 Like

Hi @James_Phillips ,

@paulinpaloalto has given a very good explanation about the way how Jupyter notebook works. As this notebook is written in Python, the computation engineer, ie. the Kernel, runs the Python Interpreter (in this case Python 3) to execute your code line by line. If you edited your code without running the code cell, the edit has no effect. The best practice is to rerun your code from start to ensure the kernel’s execution state is current with all variables and import files linked and loaded.

2 Likes