1.3 Exercises#
Exercise 1#
Course contents that contain exercises are implemented in .ipynb
files. These files can either be opened and used locally or in Google Colab by clicking on the Rocket icon in the top right corner of the book. Please open and run the following code chunk:
On your local computer (in Visual Studio Code)
On the internet (in Google Colab)
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.collections import LineCollection
colors = ["indigo", "blue", "green", "yellow", "orange", "red"]
# Create a list of half-circles with varying radii
theta = np.linspace(0, np.pi, 36)
radii = np.linspace(4, 5, num=len(colors))
arcs = [np.column_stack([r * np.cos(theta), r * np.sin(theta)]) for r in radii]
# Plot the half-circles
fig, ax = plt.subplots()
ax.set_xlim(-6, 6)
ax.set_ylim(0, 6)
ax.set_aspect("equal")
line_collection = LineCollection(arcs, colors=colors, linewidths=4)
ax.add_collection(line_collection)
ax.text(0, 1, "Welcome to psy111!", fontsize=14, ha='center')
plt.show()

Exercise 2#
Please do the following:
Create a
my_first_script.py
Python file and save it to your computerCopy the code from the previous exercise into it and run it
Exercise 3#
Please do the following:
Create a
my_first_notebook.ipynb
Jupyter notebook and save it to your computerCreate a Markdown cell and write some text
Create a Code cell and make it print the message “Hello World”
Note: You might get a pop-up telling you to install the ipykernel package. Please do so.
Exercise 4#
You have previously created a .py
Python file as well as a .ipynb
Jupyter notebook. Discuss with your neigbour:
What are the differences between these files
Can you come up with examples, where using one over the other would be preferred?
Exercise 5#
Let’s imagine the following scenario. You have completed the first year of your Master’s course and you are ready to start with your practical project! As you need to do some data analysis in Python, you want to create a new Conda envirionment so you can have all the necessary Python packages in an isolated environment and avoid any potential version conflicts.
Create a new Conda environment and call it
practical_project
Open the previously created
my_first_script.py
Python file and run it in thepractical_project
environment. Does it work?You encountered an error in the previous exercise. Please fix it.
Check the packages that are installed in the
practical_project
environmentDelete the
practical_project
environment
Hints:
Look at the “Installing Python: 1.2 Usage” section of the book if you are unsure what to do
Refer to the Conda cheatsheet if you are unsure about the required commands
Exercise 6#
Install the :emojisense: extension in Visual Studio Code, so you can add emojis to your future scripts 🚀 🥳