Email joelross@uw.edu
Zoom https://washington.zoom.us/my/joelross
Introduce to yourself to your neighbor!
Meet someone new!
In-person (section A):
Online (section B):
raw numbers
interpreted data
World's greatest assistant!
Charles Babbage's Analytical Engine (designed 1837; never built)
# This is the programming language Python
# It does math! (Applies the quadratic formula)
import math
def roots(a, b, c):
det = math.sqrt(b * b - 4 * a * c)
x1 = (-b + det)/(2 * a)
x2 = (-b - det)/(2 * a)
return (x1, x2)
x = roots(1, 5, -14)
print(x)
Nathan Sawaya
Jupyter Notebooks are interactive web applications that can be used to write and execute Python programs (as well as textual content). Notebooks can also be shared with others!
We will do all our programming in Jupyter notebooks hosted on the Ed platform online.
Access Jupyter notebooks on Ed
Type your code into a code cell.
shift + enter
to execute a cellYou can add additional cells, including text-only cells
You can "restart" the interpreter if needed
# My first program
print("Hello world!")
Use
print()
to print whatever is in the parentheses to the console. This is an example of a
function.
# My first program
print "Hello world!"
# My first program
print("Hello world!)
# My first program
print("Hello wold!")
Python 2 syntax!
First computer bug (1946)
Admiral Grace Hopper
num_cups_coffee = 3
Assignment gives a label to a value. Changing which value a variable refers to doesn't change other variables.
x = 3
y = 4
x = y # assign the value of y (4) to x
print(x) # 4
y = 5
print(x) # 4
# valid program, but what does it mean?
a = 35.0
b = 12.50
c = a * b
# much better!
hours = 35.0
pay_rate = 12.50 # needs a raise!
earnings = hours * pay_rate
# Get out.
x1q3z9ahd = 35.0
x1q3z9afd = 12.50
x1q3p9afd = x1q3z9ahd * x1q3z9afd
Good variable names describe what data they are labeling. Naming things is one of the hardest parts of computer programming.
Integers (whole numbers) and floats (decimals) are used to store numbers.
x = 2 # whole number
y = 3.5 # decimal (floating point) number
# can perform mathematical operations
z = x + y
# Use parentheses to enforce order of operations
z = 3*(x-y)**2
operator
operands
If an operand is a
float
or you use the division (/
) operator, the result will be a float.
Strings of characters (letters, punctuation, symbols, etc). Written in single or double quotes.
my_name = "Joel" # 'Joel' would be equivalent
# Can include any keyboard symbol (and more!)
course = "LIS 511: Intro to Programming!"
# Can concatenate strings together
greeting = "Hello" + " " + "World"
# Convert a number to a string to concatenate it
course_code = "LIS " + str(511)
Exercise 1.1: Variables
Go to Ed and open up Exercise 1.1: Variables. Give it a try, and if you have questions let me know!
Next time: functions!