1.1. Welcome to Jupyter Notebooks and Vocareum#

1.1.1. Quick Python Introduction#

1.1.2. Variables#

In Python, variables do not need to be declared before they are used. In other words, Python automatically decided on the correct variable type (integer, float, etc.) You can simply define a new variable using x = 5. This is just like MATLAB.

Home Activity

In the cell below, assign the value of 5 to the variable x. Then type Shift+Enter to execute the line.

# Add your solution here

We can see the value of the variable using the built-in print function. For example, to print the value of x, we would use print(x).

Home Activity

Print the value of x. Type Shift+Enter to execute the cell. (We’ll stop reminding you to do this moving forward.)

# Add your solution here

Home Activity

Now change the value of x to 8 and execute the cell.

# Add your solution here

1.1.3. Execution Order#

Note: When using Jupyter notebooks, it is very important to know that the cells can be executed out of order (intentionally or not). The state of the environment (e.g., values of variables, imports, etc.) is defined by the execution order.

Home Activity

To see this concept, rerun the cell above with the print statement.

You should see that the value 8 is now printed. This may seem problematic if you are used to programming in environments where the state is linked to the order of the commands as written, not as executed.

Again, notice that the state of the environment is determined by the execution order. Note also that the square brackets to the left of the cell show the order that cells were executed. If you scroll to the top, you should see that the code cells show an execution order of [1] , [4] , and [3], indicating the actual execution order.

There are some useful menu commands at the top of the Jupyter notebook to help with these problems and make sure you retain the execution order as expected.

Some important commands to remember:

  • You can clear the current state with the menu item Kernel | Restart & Clear Output

  • It is often useful to clear the state using the menu command just described, and then execute all the lines above the currently selected cell using Cell | Run All Above .

  • You can clear all the state and re-run the entire notebook using Kernel | Restart & Run All.

1.1.4. Vocareum Autograder#

Note

The autograder is NOT supported on Colab. All of the autograder tests and solutions have been stripped out of these notebooks.

Note

In CBE 20258, we will use Vocareum and the autograder. We will not use these in CBE 60258.

In CBE 20258, we will use the autograder in Vocareum for homework assignments, which gives you instant feedback on your work. The autograder is confirmed to allow for unlimited submissions. You just need to wait 5 minutes between submissions.

The Vocareum autograder runs code like this in the background to check your answer and provide feedback and error messages.

It is very important carefully read the assignment instructions. The autograder is simply executing logical checks behind the scenes. For example, if the assignment instructions say to store your final answer in the variable final_ans but you instead write my_ans, the autograder will mark it as wrong.