For this assignment, you will complete each of two the Problems listed below.

Starting from the COURSE_MATERIALS directory on JupyterHub, navigate to the homework folder, then to the homework0 folder. Inside, you should be able to open the main.py and variables.py files.

Using the Terminal

To run Python files in JupyterHub, we’ll need to use the terminal, which allows us to run commands. The command to run a Python file is

python FILE_NAME.py

where FILE_NAME.py is the name of the Python file we want to run (e.g. hello_world.py).

For this assignment, before we can run a Python file, we need to point the terminal (basically, our JupyterHub computer) to the homework0 folder.

To open a terminal window, click the blue “+” button in the top left corner (if you don’t have a “Launcher” window pulled up already), then select “Terminal” from the Launcher window.

Inside the Terminal window, you should see the following text (where netid is your UW NetID):

jovyan@jupyter-netid:~/COURSE_MATERIALS$ 

The ~/COURSE_MATERIALS/ tells us that our Terminal is looking at the COURSE_MATERIALS folder (even if we’ve navigated elsewhere through the folder UI on the left). To get the Terminal to look at the homework0 folder, type the following command (after the $ on your Terminal) and hit enter:

cd ./homework/homework0/

(cd stands for “change directory”, and ./homework/homework0/ is the path to get from the COURSE_MATERIALS directory to the homework0 folder)

After running the command above, the text in front of your cursor on the terminal should now read:

jovyan@jupyter-netid:~/COURSE_MATERIALS/homework/homework0$ 

Good News

For future assignments, the JupyterHub link we will provide for the assignment will take you directly to the appropriate folder, so you won’t need to change the directory of your terminal.


Now we’re in the right place and ready to start programming!

Problem 1

Manually walk through the following code and determine what the final value is for both first and second after the code is run. Then, in the main.py file, replace XXX with the final values for the variables first and second.

first = 8
second = 9
first = first + second
second = first - second
first  = first - second

In your submission, do not copy in this code. Instead, replace XXX in main.py with the values for the variables first and second.

Problem 2

In the variables.py file you’ll find the same instructions as below in commented out lines. Place your code on the line below the corresponding instruction.

  1. Assign the value 160 into a variable.
  2. Multiply the value in the variable by 2 and then store it back into the same variable.
  3. Print out the variable.

Using flake8

To use the flake8 linter (style checker), run the following command in your terminal (replace FILE_NAME.py with the name of the Python file you want to check):

flake8 FILE_NAME.py

The output from this command lists all of the style issues found by flake8 and their corresponding line numbers in your Python file.

Info

For this assignment, we are not grading on linter (flake8) errors, but you should practice good style and address all linter errors as shown by flake8.


Don’t forget to take the syllabus quiz and submit your Python files to Gradescope!