Session 1: Introduction to Jupyter Notebook#

Perform the following Jupyter notebook operations:

  • Run notebook

  • Change a cell and re-run the cell

  • Add a new line/cell to a notebook

  • Download the workshop material with code cell

  • Unzip the downloaded zip file with code cell

Please follow the instruction at each cell.

1. Run notebook#

Please run the code cell below.

You can hit (Ctrl + Enter) to run current cell or (Shift + Enter) to run current cell and go to next cell. Alternatively, you can click run cell in the toolbar above.

message = "Hello World"
print(message)

2. Change cell and re-run the notebook#

Modify the message of the print statement below to say “Hello IN-CORE” and run the current cell.

message = "Hello World"
print(message)

3. Add a new line and execute it#

Add a new cell below to this notebook. On the new line, modify the message variable to print your name.

4. Download a zip file of the workshop material#

URL: https://github.com/IN-CORE/incore-docs/raw/main/workshops/20231115/workshop_2023-11-15.zip

Please run the following code to download a zip file. Please make sure that it appears in your file browser (left panel)

# import requests module
import requests
# set URL and get file contents
url = "https://github.com/IN-CORE/incore-docs/raw/main/workshops/20231115/workshop_2023-11-15.zip"
filename = "incore-workshop.zip"
headers = {"user-agent": "Wget/1.16 (linux-gnu)"}
r = requests.get(url, allow_redirects=True, stream=True, headers=headers)
# write the contents to a file
open(filename, "wb").write(r.content)

5. Unzip the downloaded zip file#

Please run the following code to unzip the downloaded zip file. Please make sure that all the workshop materials appear in your file browser (left panel) jupyter-lab-leftpanel.png

# import zipfile module
import zipfile
# extract the zipfile
with zipfile.ZipFile(filename, "r") as zip_ref:
    zip_ref.extractall()