Hi, i’m a student and really need help on this basic topic for a one day assignment. Trying to download appropriate .py file from Jupyter notebook. Any help would be appreciated, please!
I’ve corrected all the errors in Jupyter Notebook. However, when I go to download it as a Python file, I get the following (screenshot below). It is a .py file, but the entire script is missing from it. Currently, I am stuck on how to get the appropriate file where the full script is there. Can someone please advise?
I also attached a screenshot of my Jupyter Notebook, which I accessed through Anaconda Navigator. I’m on Windows/PC.
It’s possible that when you open the file, your computer will simply run the script by default (in other words, it defaults to python.exe as the program to open .py files). Try opening it in a text editor.
Click on “Show in folder” (the open folder icon) and then, in the File Explorer, right-click on the file and click “Open with…” and pick the editor that you’re going to use.
Ok, when I open in Notepad i get this (below), which looks correct. But i’m supposed to submit the assignment as a .py file, so I just wanna make sure i’m not missing anything?
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import platform
vers = platform.python_version()
assert vers[0] == '3', "You must use Python 3, "+vers+" is not acceptable"
print("Python 3 confirmed.")
num_cakes=input("How many cakes would you like to make?")
recipe_mult=12/int(num_cakes)
sweet_butter=str(125*recipe_mult)+"g sweet butter"
sugar=str(225*recipe_mult)+"g sugar"
eggs=str(max(1,round(recipe_mult)))+" eggs"
vanilla=str(recipe_mult)+" tsp vanilla extract"
chocolate=str(recipe_mult)+" tsp chocolate extract"
flour=str(225*recipe_mult)+"g flour"
salt=str(0.5*recipe_mult)+" tsp salt"
chips=str(200*recipe_mult)+"g chocolate chips"
print(sweet_butter)
print(sugar)
print(eggs)
print(vanilla)
print(chocolate)
print(flour)
print(salt)
print(chips)
Well the good news is that you’ve already run the file several times (when you were just clicking on it), and if that’s the output you’re looking for then you’re all set.
I can’t speak for any coding standards that your course might expect though. Maybe they want a certain style or specific implementation.