print('Welcome to Jupyter Notebook!')
Welcome to Jupyter Notebook!
Individual code or Markdown blocks are called cells. If there is any, the output from executing a cell is printed below it.
nums = [13, 137, 1347]
for num in nums:
# prime numbers are greater than 1
if num > 1:
for i in range(2,num):
if (num % i) == 0:
print(num,"is not a prime number")
print(i,"times",num//i,"is",num, "\n")
break
else:
print(num,"is a prime number\n")
else:
print(num,"is not a prime number")
13 is a prime number 137 is a prime number 1347 is not a prime number 3 times 449 is 1347
Variables will maintain their values throughout a notebook session.
print("the nums array is: ", nums)
the nums array is: [13, 137, 1347]
But, be careful. If we were to reassign the nums array and run the prime number cell it will use the new value "one two three" and throw a TypeError. For this reason, the numbers in brackets next to a code cell exist to indicate the order in which they executed.
nums = "one two three"
# If I now reran the prime number cell, this is what would happen:
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-53-5da4b71aaa64> in <module>() 1 for num in nums: 2 # prime numbers are greater than 1 ----> 3 if num > 1: 4 for i in range(2,num): 5 if (num % i) == 0: TypeError: unorderable types: str() > int()
It's also possible to import and use your favorite python libraries.
from IPython.display import Image
Image("images/jupiter.jpg", width="50%")
import pandas as pd, numpy as np
df = pd.DataFrame(np.random.randn(10,5))
df
0 | 1 | 2 | 3 | 4 | |
---|---|---|---|---|---|
0 | 0.441549 | 0.089738 | 1.744346 | 2.258575 | 0.426664 |
1 | 0.553689 | -0.275493 | -0.510059 | 1.242461 | 2.455822 |
2 | 0.840024 | 1.177655 | -1.655240 | -0.741060 | 0.592697 |
3 | -0.627262 | -0.755453 | -1.440758 | -0.674110 | -1.067317 |
4 | -1.105372 | 0.625164 | -0.071721 | 0.481504 | 0.236426 |
5 | 0.509087 | 0.231790 | -1.800046 | -1.122785 | 1.039416 |
6 | 0.512036 | -0.227839 | -0.929626 | 0.899213 | 0.116162 |
7 | 0.222015 | 0.638809 | 0.362991 | -1.449985 | 1.138178 |
8 | -1.413669 | -1.734242 | -0.931476 | -2.319323 | 0.764478 |
9 | -0.291182 | 0.501667 | -1.191091 | -0.822639 | -0.659891 |
import matplotlib.pyplot as plt
import numpy as np
N = 50
x = np.random.rand(N)
y = np.random.rand(N)
colors = np.random.rand(N)
area = np.pi * (15 * np.random.rand(N))**2
plt.scatter(x, y, s=area, c=colors, alpha=0.5)
plt.show()