Python setup · 3 of 3
Run a Python file on Windows or Mac
Use the supplied script to see what happens when Python reads answers and prints a result. Then use the same steps to run any file in your workbook.
Open the extracted workbook
Start from the setup check in the first lesson. If Python is installed, download and extract the workbook ZIP. Open the folder that contains workbook.txt. Inside setup you’ll find run_python.py and run_python-input.txt.
Open the terminal in the workbook folder. On Windows, copy the folder path from File Explorer. In Command Prompt type cd /d, a space, and the folder path in double quotes. On Mac, type cd and a space in Terminal, drag the folder from Finder into the window, and press Return.
Check where you are before running a file. On Windows, type dir and press Enter. On Mac, type ls and press Return. You should see workbook.txt and the setup and lessons folders.
Windows · run a file and enter answers
In Command Prompt, run the file below. The first word starts Python and the rest tells it which file to open.
py setup\run_python.pyWhen Python asks for a name, type Sam and press Enter. When it asks where you’re sending from, type Base Camp and press Enter. After the result, the Command Prompt is ready for another command.
What you should see · Sam is sending from Base Camp.
Command Prompt can also read the supplied answers from a file. The < symbol sends the lines in that text file to the program. Use Command Prompt for this command.
py setup\run_python.py < setup\run_python-input.txtWhat you should see · Sam is sending from Base Camp.
Mac · run a file and enter answers
In Terminal, run the file below. The first word starts Python and the rest tells it which file to open.
python3 setup/run_python.pyWhen Python asks for a name, type Sam and press Return. When it asks where you’re sending from, type Base Camp and press Return. After the result, the terminal is ready for another command.
What you should see · Sam is sending from Base Camp.
Terminal can also read the supplied answers from a file. The < symbol sends the lines in that text file to the program.
python3 setup/run_python.py < setup/run_python-input.txtWhat you should see · Sam is sending from Base Camp.
Run the same file in VS Code or Coding Studio
In VS Code, open the workbook folder, then open setup/run_python.py from the Explorer sidebar. Click Run Python File. The Terminal panel at the bottom is where you type Sam and Base Camp, pressing Enter after each line.
In browser-based Coding Studio, programs that read input have a Program input box. Type your answers there on separate lines before choosing Run. The output appears below. The Check button supplies the input for its own cases.
Repeat these steps for the course files
Open workbook.txt and find the folder listed under Lesson files. In File Explorer or Finder, open that folder. It contains instructions.txt, example.py when the lesson has an example, and starter.py.
Use the same cd steps to enter the lesson folder. Run the example first. Edit starter.py in your code editor, save it, and run it again. Use the Windows pair below in Command Prompt or the Mac pair in Terminal.
py example.py py starter.py python3 example.py python3 starter.pySome workbook programs wait for input without printing a question. The lesson lists the lines to enter. If you need to stop a program and get the terminal prompt back, press Ctrl+C. On Mac, use Control for this shortcut.
Install packages when a local project needs them Open the Python course →