Module 1 - Practice - Basic Python
Exercise 0:
How to make a copy of a pre-existing Nextjournal notebook that you can edit
How to create a new Python code cell
How to undo one or more changes to a notebook
Bonus: How to delete a cell
Bonus: How to move a cell up or down
Exercise 1:
Create a variable that has an int value and another variable that has a float value. Write code that prints the product (multiply the two variables together).
Hint: To multiply numbers in Python, use the asterisk sign (*).
# Here is a code cell for you to use for exercise 1
Can you figure out how to make a new code cell for exercise 2? If you need them, the instructions are written at the bottom of this notebook.
Exercise 2:
Make a list of all the months in the year. Write code that uses a loop to go through the list, print out the month and the number of characters (length) for each month word.
Exercise 3:
Create a dictionary with keys "movie" and "season", with the values being your favorite movie and season. Then write code to print out "My favorite [key] is [value]".
Exercise 4:
Create a customized function (def) that divides two variables and returns the result of their division. Then call your function using the variables you made in Exercise 1.
Hint: To divide numbers in Python, use the forward slash (/).
How to Make a New Cell
To make new code cells in Nextjournal, you can simply move your mouse over a pre-existing cell (text or code). You should see that a + icon has appeared immediately to the bottom left corner of the cell. Try clicking on that + icon, then select "Code Cell: Python" from the dropdown selection.
You've reach the bottom of this notebook! Click here to go back to the top of this notebook.
Or, go back to the course outline