Watch the videos below, read through the materials linked to below the videos as well as Section 4.1 through 4.3 of the Python Tutorial, and complete the assigned programming problems. Please get started early, and come to office hours if you have any questions!
Recall that to make notebook cells that have Python code in them do something, hold down the 'shift' key and then press the 'enter' key (you'll have to do this to get the YouTube videos to run). To edit a cell (to add answers, for example) you double-click on the cell, add your text, and then enter it by holding down 'shift' and pressing 'enter'
This assignment is due by 11:59 p.m. the day before class, and should be uploaded into the "Pre-class assignments" dropbox folder for Day 6. Submission instructions can be found at the end of the notebook.
In [ ]:
# Imports the functionality that we need to display YouTube videos in
# a Jupyter Notebook.
# You need to run this cell before you run ANY of the YouTube videos.
from IPython.display import YouTubeVideo
In [ ]:
# Don't forget to watch the video in full-screen mode!
YouTubeVideo("BTXyE3KLIOs",width=640,height=360) # numpy
Question 1: In the cell below, import the numpy module and then create two arrays with the same number of elements in each one (pick the number of elements and the value of each yourself, making sure they're numbers and not strings!). Then, add those arrays together and store it in a third array, and print it out. Sort the values of the third array, and print that out again.
In [ ]:
import numpy as np
# put your code here!
Question 2: Now let's use numpy and pyplot together (you learned about pyplot in a prior class). We're going to use numpy's linspace
method (which you can learn about by typing this:
np.linspace?
in the cell below. Use linspace
to create an array called x
with 10 values ranging from x=0 to $4\pi$, and then a second array called y that is the sine of x. Then, plot x vs. y with a red line!
Hint 1: use np.sin()
, which you can find more about by typing np.sin?
in the cell below
Hint 2: look at the pre-class notebook from previous classes - what did you do to make plots there? Alternately, check out the Pyplot tutorial.
In [ ]:
%matplotlib inline
import matplotlib.pyplot as plt
# put your code here!
In [ ]:
# Don't forget to watch the video in full-screen mode!
YouTubeVideo("cozbOliNwSs",width=640,height=360) # Boolean logic and if statements
Question 3: Write a program that compares three variables v1, v2, and v3 (not necessarily the variable names) and does the following using if statements:
Try several values of v1, v2 and v3 and ensure that you see the correct behavior.
In [ ]:
# write your program here, using multiple cells if necessary (adding extra cells using
# the 'Cell' menu at the top of this notebook). Don't forget that you can execute
# your program by holding down 'shift' and pressing 'enter' in each cell!
In [ ]:
# Don't forget to watch the video in full-screen mode!
YouTubeVideo("VnTN5sFIPD0",width=640,height=360) # loops in python
Question 4: Write two small programs that do the following:
In [ ]:
# Program 1 here
In [ ]:
# Program 2 here
In [ ]:
# Program 3 here
In [ ]:
from IPython.display import HTML
HTML(
"""
<iframe
src="https://goo.gl/forms/F1MvFMDpIWPScchr2?embedded=true"
width="80%"
height="1200px"
frameborder="0"
marginheight="0"
marginwidth="0">
Loading...
</iframe>
"""
)