Date |
In Class |
Code |
On Your Own |
|
This document is updated frequently, so remember to refresh your browser.
|
|
Week 14 |
November 28 |
- Introducing objects in Python
- An object is a thing with its own state, along with operations that modify or observe that state
- A type of object is defined by a
class
- Basic terminology
- functions defined in a class definition are traditionally called "methods"
- the
__init__ method is known as a "constructor"
- The variables defined in the
__init__ method are called "instance variables", since each instance of the class has its own copies of these variables.
|
cr_class.py
cr_class_test.py
cr_class_with_tax.py
Picture of the cash register instances in pythontutor
|
Read How to Think Like a Computer Scientist, Chapter 14.
|
November 30 |
- Modeling an object in the real world
- Describing an interaction with the object
- Determining the operations (methods) that are needed
- Writing a usage example or test case
- Defining the class and determining what instance variables are needed
|
coffeemaker.py
coffeemaker_test.py
|
There will be a group quiz covering the basics of objects and class definitions in Python. Read How to Think Like a Computer Scientist, Chapter 14.
|
December 2 |
- Using an object as a simple data container
- Reading a file and creating a list of objects
|
contacts.py
contact_test.py
contact_info.txt (sample text file)
|
|
|
Week 13 |
November 14 |
|
|
|
November 14 |
- More about nested loops
- Using a 2-dimensional grid
- A "grid" is just a list of lists
- Each element of the grid is one row, consisting of a list
- The element at row
r , column c is grid[r][c]
- The number of rows is
len(grid)
- The number of columns is
len(grid[0])
|
duplicate_letter.py
grid_test.py
|
|
November 18 |
|
|
|
|
Week 12 |
November 7 |
- A variable in a module that is declared outside of all functions is a global variable
- All functions can read the values of global variables
- To update a global variable, must use the
global keyword
- Global variables are one way a program can keep track of state
- Use with caution: lots of global variables makes code very difficult to verify and maintain
|
cr.py
cr_test.py
number_game.py
number_game_ui.py
|
|
November 9 |
- Reading text files
- End-of-line characters
- The escape sequences
\t , \n , and \r
|
file_read_test.py
(You'll need a file called testfile.txt in your program's current working directory in order to run this )
|
|
November 11 |
|
|
|
|
Week 11 |
October 31 |
- Lists are mutable!
- item assignment
- appending or inserting elements
- deleting elements
- Common list operations - append, insert, pop, remove, index, sort
- The
del keyword
|
loop_for_user_input_with_list.py
list_modification_example.py
|
- Read How to Think..., Section 10.14 and related sections
|
November 2 |
- Operations that remove elements from a list
remove(item) , pop(pos) , and the del keyword
- In general, you should not try to remove elements while you are iterating over the list! (see examples)
- List variables are references, understanding
lst = temp versus lst[:] = temp
|
list_remove_examples.py
|
- There will be a group quiz on list methods, e.g. see How to Think..., Section 10.14 and related sections
|
November 4 |
- Binary arithmetic as a kind of boolean operation
- Logic gates for
and , or , and not
- Combining logic gates to make a circuit for binary addition
- Registers for storing values, the system clock
|
|
|
|
Week 10 |
October 24 |
- Introducing while-loops
- Anatomy of a while-loop
- 1. Loop body (What is the repeated action?)
- 2. Initialization (What do I need to get started?)
- 3. Condition (How do I know when to stop?)
|
while_loops.py
interest.py
|
|
October 26 |
- Examples with while-loops
- Use a for-loop when iterating over a known sequence or range of values
- Use a while-loop when the number of iterations is difficult to predict or bound
- Thinking about types of loops
- Do I need a for-loop or a while-loop?
- Do I need to process every piece of data, or can I return as soon as I "find" something?
- (For string or list) Can I just iterate over the elements, or do I need to use an index?
|
loop_for_user_input.py
primes.py
|
- There will be a group quiz on while-loops. Read Eels, Chapter 17.
|
October 28 |
- Using the string
split() method
- Using
split() with a delimiter
- Alternatives to using
split()
- Even really smart programmers make mistakes!
- Tracking down errors using the Wing 101 debugger
|
sum_string.py
|
|
|
Week 9 |
October 17 |
- Using an index to access an individual character of string
or list,
s[i]
- Using the bracket notation to get a substring or slice
of a string or list,
s[i:j]
- Loops using an index
|
double_letter.py
switch_first_and_last.py
|
|
October 19 |
- String operations are methods rather than built-in functions
- We write
s.upper() , not upper(s)
|
|
- There will be a group quiz on indices and substrings. Read Eels, Chapter 13
- See Eels, Chapter 14 on string operations.
|
October 21 |
- More examples of loops with indices
- The idea of a nested loop
|
duplicate_letter.py
|
|
|
Week 8 |
October 10 |
- Using an auxiliary variable as an accumulator or counter in a for-loop
- The search pattern - once you find something, don't "un-find" it
|
loop_counter_examples.py
|
|
October 12 |
- Using accumulator pattern with multiplication or string concatenation
- Using an early return in a loop for searching
-
|
more_loop_counter_examples.py
|
- There will be a group quiz covering for-loops. Review your notes from Monday and read Eels, Chapter 16
|
October 14 |
- Binary (base 2) numbers
- Encoding characters as numbers
- Comparing strings, lexicographic ordering
-
|
|
|
|
Week 7 |
October 3 |
|
|
|
October 5 |
- More about for-loops
- Using the loop variable
- More about
range expressions
- Iterating over other types of lists
|
turtle_polygon.py
loop_examples.py
ninetynine.py
|
- See How to Think... Sections 4.4 - 4.7
|
October 7 |
- Problem-solving strategies
- Can I solve a part of the problem?
- Can I solve a related, simpler problem?
Procedural decomposition: break a problem into sub-problems, and compose the solutions together
|
arc_experiment.py
|
- See the summary at the beginning of the homework 3 spec
|
|
Week 6 |
September 26 |
- DeMorgan's laws
- Using multiple return statements
|
grade_calc_multiple_returns.py
|
|
September 28 |
- Using a "unit test" to quickly check results from a function
- Incremental development - write code a little at a time and test frequently
|
postage.py
postage_test.py
|
- There will be a group quiz on Chapter 8 (value-returning functions)
|
September 30 |
- Exam review
- Using boolean variables and boolean expressions
- Unit testing and incremental development, con't
- Function that determines leap years
|
leap.py
leap_test.py
|
|
|
Week 5 |
September 19 |
- Defining functions
- Arguments are the values you pass to the function when you call it, can be any expression of the right type
- Parameters are the variables listed in parentheses in the function definition; they get their values from the arguments you supply
- Parameter variables are "local" (not visible outside
the function body)
- Flow of control in function calls
|
ninetynine.py
area_printer.py
|
|
September 21 |
- Value-returning functions and the
return statement
- Two kinds of functions
- Functions that return a value (like
len , pow
- Functions that perform some action (like
print ) and usually don't return a value
- Using our own modules
|
area.py
area_test.py
carpet_cost_calculator.py
|
|
September 23 |
- The boolean operators
and , or , and not .
- Truth tables
|
grades_ui.py
|
- There will be a group quiz today covering Eels, Chapter 7
- Read Eels, Chapter 9
|
|
Week 4 |
September 12 |
- Recap: for-loops and the idea of a statement block
- Conditional statements: using
if and if...else
|
hats.py
|
|
September 14 |
- Nested conditional statements
- Multiple alternatives and the
elif keyword
|
grades.py
|
- There will be a group quiz covering Eels, Chapter 5
- Read Eels, Chapter 6
|
September 16 |
- Problem-solving with conditional statements
|
Sally orders lunch (video)
Our solution in pseudocode
MU parking rates
parking.py
|
|
|
Week 3 |
September 5 |
|
|
|
September 7 |
- Using built-in Python functions
- Reading input with the
input function
- Type conversion functions
int , float , and str
- String concatenation using the
+ operator
|
input_test.py
|
- Read Eels Chapter 4
- Start the homework!
|
September 9 |
- Recap:
input and number conversions
- Integer arithmetic vs. floating point arithmetic
- Floating point arithmetic is almost never exact
- Try calculating (1/3) * 300 on a pocket calculator
- Try calculating (29 / 100) * 100 in Python
- Modules such as
math or turtle and how to find documentation
- The basic
for loop: repeating some action a fixed number of times
|
quiz_sept_9.pdf
turtle_loop_test.py
loop_test.py
|
- There will be a group quiz on topics from Eels, Chapter 4
- We will do much more with for-loops and ranges in a couple of weeks, but you can start reading more about them in ThinkCS (How to Think Like a Computer Scientist), Chapter 4
|
|
Week 2 |
August 29 |
- Defining variables
- The assignment operator
=
- Use
== to check equality, not =
- Example: making change
- A general problem-solving strategy: start with a simple, concrete example
- E.g., to solve the problem of making change for an unknown amount, first work it out for 67 cents.
|
change.py
|
- Read Eels Chapter 2 and try the examples
- Remember to go to lab this week!
|
August 31 |
- A general problem-solving strategy: start with a simple, concrete example
- E.g., to solve the problem of making change for an unknown amount, first work it out for 67 cents.
- Small group problem-solving exercise.
|
class_exercise_aug_31.pdf
|
|
September 4 |
- Problem-solving strategies reviewed: start with a simple, concrete example
|
time.py
|
|
|
Week 1 |
August 22 |
|
|
- Read the syllabus!
- Read Eels Chapter 1!
|
August 24 |
- Formal syntax of a programming language
- keywords, operators, identifiers, literal values
- Some ways to experiment with Python code:
- The "activecode" windows in the textbooks
- The Python interactive shell
- Philip Guo's
Python Tutor
(aka the "codelens" tool in the textbooks)
- To create a program or script that we want to save:
- Use any text editor
- Use an "Integrated Development Environment" or "IDE" such as Wing 101 or IDLE
- Writing our first Python program
|
hello.py
|
- Read Eels Chapter 2 and try the examples
- If you want to get started writing programs, take a look at the
Lab 1 from last year and see the page on "Wing 101". (All the computers in the Pearson labs should have Wing 101 installed.)
|
August 26 |
- Operators and literal values in Python
- Integer division and the "mod" operator (
% )
- Some of Python's types:
int - whole numbers
float - numbers with a decimal point
str - strings of text
bool - the values True and False
- Making syntax errors and interpreting error messages
- Role of the Python interpreter
|
|
|