Goals for today's pre-class assignment

  • Write a Python program to make simple calculations
  • Work with number and string data types
  • Work with the list data type
  • Learn how to do order-of-magnitude approximations

Assignment instructions

Watch the videos below, read through Section 3.1 of the Python Tutorial, and complete the assigned programming problems and questions. 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 3. 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 [ ]:
# Display a specific YouTube video, with a given width and height.  
# WE STRONGLY RECOMMEND that you can watch the video in full-screen mode
# (much higher resolution) by clicking the little box in the bottom-right 
# corner of the video.

YouTubeVideo("cCLB1sNpNYo",width=640,height=360)

Question 1: In the cell below, write a simple program to calculate the area of a rectangle where you give it the length and width of the rectangle as variables, store it in a third variable, and print out the resulting area. Add comments to each line to explain what you're doing!


In [ ]:
# write your program here.  Don't forget that you execute your program by holding
# down 'shift' and pressing 'enter'

In [ ]:
# Don't forget to watch the video in full-screen mode!

YouTubeVideo("yv7klK57Ezc",width=640,height=360)

Question 2: In the cells below, create a variable containing a floating-point number and a second variable containing an integer. Turn both into strings and concatenate them, and store it in a new variable. Finally, print out the last value in your newly-concatenated variable. You can use more than one cell if you need to print out multiple quantities!


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("TJ_bGrigAMg",width=640,height=360)

Question 3: In the cells below, create a list that contains, in this order:

  1. your first name as a string
  2. your age as a floating-point number
  3. your room or apartment number as an integar

Print this list out. Then, after you print it out, replace your first name in the list with your last name, and replace your age with the current year as an integer. Then, append one or more new variables (of whatever type), print out the length of the list using the len() function, and then print out the entire list again!


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("rVhV_9YZZXw",width=640,height=360)

Question 4: As a human being, you need water to survive. How many Olympic-sized swimming pools could you fill with the water an average human being will drink in their lifetime? In the cell below, explain how you would solve this problem and provide an estimate of the answer (and range of possible solutions).

Put your answer here!

Assignment wrapup

Please fill out the form that appears when you run the code below. You must completely fill this out in order to receive credit for the assignment!


In [ ]:
from IPython.display import HTML
HTML(
"""
<iframe 
	src="https://docs.google.com/forms/d/e/1FAIpQLSc3fbJob95nAMX4KoYdhql4aco4i2_nagMHUqazRRt8g0JMVA/viewform?embedded=true" 
	width="80%" 
	height="1200px" 
	frameborder="0" 
	marginheight="0" 
	marginwidth="0">
	Loading...
</iframe>
"""
)

Congratulations, you're done!

Submit this assignment by uploading it to the course Desire2Learn web page. Go to the "Pre-class assignments" folder, find the dropbox link for Day 3, and upload it there.

See you in class!