Post date: Aug 30, 2011 4:33:35 PM
Announcements
Chapter 3 Quiz now has 3 attempts possible.
Deadline extended until 31-August 10:00 pm
Rick added the new page Python Resources (link to the left)
It includes links for installing Python 3.2 on Mac and Windows machine.
It also has links to Python tutorials and documentation.
Note: John Zelle's Appendix A, pages 469..477 provides a concise reference.
Programming Project 1 Linked. Due next Tuesday, 6-Sep, at 4:00 pm
Homework
Work on Project 1: Three programs (in files lightning.py, energy.py, and population.py)
Lecture Outline
1) Consider Project 1 (see Projects page)
Recommended: Read the grading criteria (it's not often you're told in advance how you work is graded)
You may put all code in def main(): like the book, but you don't need to
If you do, indent all code you want to execute. 4 spaces is typical
And at the bottom, add main() that calls your main() function
2) Chapter 3: Computing with Numbers
There are two types of numbers int as in 12345 or -5 and double as in 4.5 and -1.2e+3
float has limited precision
int doesn't have overflow, cool
Use / for regular division 5.0/2.0 is 2.5, so is 5/2 even though both operands are int
When operands are mixed, promote int to float
for example, (6 + 9.9) becomes 6.0 + 9.9 = 15.9
Integer arithmetic is sometimes useful. Use // to get an int
13 // 5 is 2 (the quotient)
13 % 5 is 3 (the remainder)
int('123') is the integer 123
float('123') is the floating point number 123.0
float('not a number') and int('x') are ValueErrors
3) Code demo: Compute the minimum number of coins to return for any given change from 0 to 99 cents:
The local supermarket has asked you to develop a program to return change to their customers with
the caveat that you always compute the minimum number of coins. This supermarket doesn't want to
give a customer 99 pennies for change of 99 cents. Rather, they prefer to return 3 quarters, 2 dimes,
and 4 pennies (the only coins to return for change are quarters, dimes, nickels , and pennies).
To begin, write a Python program that reads the amount of change assumed to be in the range
of 0..99 and prints the number of quarters, dimes, nickels, and pennies. Here is a sample dialog:
Enter change: 41
Quarter: 1
Dimes: 1
Nickels: 1
Pennies: 1
4) In class activity (see handout)