Course Announcements
A2 due tonight (11:59 PM)
E1 is on Thursday
closed notes in-class (12.5 pts) + open notes/open Internet take-home (2.5 pts)
answer keys available
no office hours on Thursday
CL3 due Friday
Notes:
CL1 & A1 Scores Posted
A1 regrades - fetch feedback on datahub; open for 3d; post privately to Instructors on Piazza
CL - if you spent an hour of dedicated effort and didn’t get full credit, reach out to me
Exam 1 Review#
In-class:
bring a writing utensil
20 Questions
8 multiple choice
9 fill in the blanks
1 draw arrows from concept to code
2 short answer
Take-home:
2 Questions
1 read/debug code
1 write a function
released at 3:30 PM; due 11:59 PM
fewer
assert
s than assignments
Big Topics Covered#
Variables & Data Types
Integers, Floats, Strings, Booleans, Lists, Tuples, Dictionaries
Operators
logical, math, comparison, membership
Functions
definition & execution
default values
keyword vs. positional
Conditionals
if/elif/else
Expectations:
Be able to explain/describe main concepts and vocabulary
Be able to read code and determine what it does
Be able to debug given code when a task is specified
Describe the logic/code needed to accomplish a task
Questions?
Indexing#
The list burritos
has been provided in the cell below for you.
Use the burritos
variable and indexing to generate each of the four variables at left below, so that each stores the output at right below. For example, burritos_a
should refer to burritos
in its answer and use indexing to store the string ‘Cali’.
burritos_a
|'Cali'
burritos_b
|['Adobada', 'Bean and Cheese', 'Steak Ranchero', 'Carnitas']
burritos_c
|['Cali', 'Steak Ranchero']
burritos_d
|['Chicken', 'Chile Verde', 'Adobada', 'Steak Ranchero']
# this variables provided for you
# this cell is read-only (cannot be changed)
burritos = ['Chicken', 'Carne Asada', 'Chile Verde', 'Cali',
'Adobada', 'Bean and Cheese', 'Steak Ranchero',
'Carnitas']
# answer here
For iclicker: A) I did it. B) Tried and Stuck. C) I’m lost.
Debugging#
Find and fix the errors in make_change()
.
This function should make_change(money)
- turns decimal dollars into a number of coins, returning how many quarters and pennies to return. (We will just work with two coin types for now, to keep things simple)
def make_change(money)
# turn it from dollars into cents
money = money * 100
# how many quarters to give
quarters = money // 25
# how much money is left after the quarters
money = money - quarters*10
# how many pennies to give
pennies = money / 1
# debug here
# test out your edits here
For iclicker: A) I did it. B) Tried and Stuck. C) I’m lost.
Define a function#
Write a function with the following properties:
'''
max_of_3(n1, n2, n3) - returns the maximum of three numbers
inputs:
n1, n2, n3 - the numbers
returns:
the biggest number among n1, n2, n3
NB: you may assume there are no ties among n1, n2, n3;
and you don't need to error check the inputs
'''
# answer here
# test here
For iclicker: A) I did it. B) Tried and Stuck. C) I’m lost.