Python example

Download exercises zip

Browse files online

Example of notebook for exercises in Python files

What to do

  • unzip exercises in a folder, you should get something like this:

python-example
   python-example.ipynb
   lab1.py
   lab1_test.py
   lab1_sol.py
   lab2.py
   lab2_test.py
   lab2_sol.py
   jupman.py
   my_lib.py
  • open the editor of your choice (for example Visual Studio Code, Spyder or PyCharme), you will edit the files lab1.py and lab2.py

  • Go on reading this notebook, and follow instuctions inside.

Let’s begin

You are going to program a simulator of bouncing clowns. To do so, we are going to load this module:

[2]:
import local
[3]:
local.gimme(5)
It was a 5 indeed

Download test data

Local file:

Global image

cc-by-2313

Local exercise image

leaves-983423

Python tutor

[4]:
x = [1,2,3]
y = 6

jupman.pytut()
[4]:
Visualization provided by Python Tutor
[5]:
y = [1,2,3]

jupman.pytut()
[5]:
Visualization provided by Python Tutor

Start editing lab1.py in text editor

[6]:
from lab1_sol import *

add

Implement add function:

[7]:
add(3,5)
[7]:
8

sub

Implement sub function

[8]:
sub(7,4)
[8]:
3
[ ]: