#!/usr/bin/env python # coding: utf-8 # # Hello World # In[13]: print('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. # # ### Snippet to check for prime numbers # In[54]: nums = [13, 137, 1347] # In[55]: 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") # ### A note about state # Variables will maintain their values throughout a notebook session. # In[51]: print("the nums array is: ", nums) # 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. # In[53]: nums = "one two three" # If I now reran the prime number cell, this is what would happen: # ### Importing libraries # # It's also possible to import and use your favorite python libraries. # In[14]: from IPython.display import Image # In[15]: Image("images/jupiter.jpg", width="50%") # In[16]: import pandas as pd, numpy as np # In[31]: df = pd.DataFrame(np.random.randn(10,5)) df # In[3]: 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() # In[ ]: