Using Jupyter (Good), Exercises

Exercise 1 (Learning to interrupt)  

Copy and paste the following simple, innocent code and run it.

while True:
    print('*', end='')

Your Jupyter Notebook should be printing like crazy right now.

Figure out how to interrupt the proceedings (Kernal).

Exercise 2 (Resetting & Restarting the Kernal)  

Run the following:

print = 'PRINT'

Now try:

print('Hello World')

Yes, you have messed up your print() function1.

Fix this by Restarting the Kernal. This will also restart the Python interpreter.

Exercise 3 (Timing Stuff) The two code examples below achieve the same end result.

squares = [i**2 for i in range(10)]
squares = list()
for i in range(10):
    squares.append(i**2)
  1. Verify that both codes give the same result (HINT: print()).
  2. Use %%timeit to measure the execution time for each example.
  3. Discuss with a friend to understand what each of the numbers in the %%timeit output represents and write down their meanings.
Back to top

Footnotes

  1. Okay, okay it was me, but you pressed the button.↩︎