Generate .py on Jupyter Notebook

Hello everyone, I’ve just finnished this exercise here and would like to know how to test it properly and possibly generate a .py file. I find it a bit harder to debug and run the program here. I’d preffer to run it on the python shell or so. Thanks