C1W2 Cannot pass the grader even I have passed all the tests

Hi,
I have done the notebook according to the guidelines and have passed all the tests in the notebook. However, the grade of my notebook when I submit is 0 (having saved the notebook already) with the information of “There was a problem compiling the code from your notebook, please check that you saved before submitting. Details:
name ‘untrained_model’ is not defined”
Please help review, thank you.

To help me assist you,

Please click on my name to start a private message. Then, attach your notebook as a .ipynb file. Please note that mentors cannot access your Coursera Jupyter workspace, so sending the notebook in a .ipynb format is essential.

Please don’t use global variables in the assignment unless you absolutely have to. In the function train_mnist, invoke the function to create a new compiled model instead of relying on untrained_model

Thank you, I change my code and it works successfully. However, I am grateful if you can explain further why the global variable shouldn’t be used. I’m a non-tech person trying to learn new thing about technology so pardon if the question may seem obvious.