Hello World Notebook!

This is an example of the Jupyter .ipynb document format

Open In Colab Download .ipynb

# This is an executable cell
print("Hello World!")
Hello World!
# Setting variables in Python
x = 42
x
42
# Variables persist after being set in previously executed cells
x
42

Markdown Cells Support Rich Formatting

You can use: - Bold and italic text - Lists (like this one!) - Links - inline code - And even LaTeX math: \(E = mc^2\)

This makes notebooks great for explaining your code!

# You can perform calculations across cells
y = 10
z = x + y
print(f"x ({x}) + y ({y}) = {z}")
# Notebooks make it easy to import and use libraries
import math
import random

# Generate a random number and calculate its square root
num = random.randint(1, 100)
sqrt_num = math.sqrt(num)
print(f"The square root of {num} is {sqrt_num:.2f}")
The square root of 29 is 5.39
# Visualizations appear inline!
import matplotlib.pyplot as plt
import numpy as np

x_values = np.linspace(0, 10, 100)
y_values = np.sin(x_values)

plt.figure(figsize=(8, 4))
plt.plot(x_values, y_values)
plt.title('Sine Wave')
plt.xlabel('x')
plt.ylabel('sin(x)')
plt.grid(True)
plt.show()

What Happens When There’s an Error?

Run the cell below to see how notebooks handle errors.

The error appears in the output, but other cells continue to work.

# This will cause an error
result = 10 / 0
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
Cell In[9], line 2
      1 # This will cause an error
----> 2 result = 10 / 0

ZeroDivisionError: division by zero