Outline for April 10, 2009
Reading: §3.1–3.4
- Clarification from last class
- [1, 9, 2] is a list of 3 numbers
- range(1, 9, 2) is the same as [1, 3, 5, 7]
- range(9, 1, −2) is the same as [9, 7, 5, 3]
- range(0, 5, −1) is the same as [ ] (an empty list)
- Formatted printing using print statement
(see print.py)
- Comments on homework
- Please do not turn in Microsoft Word (“.doc”) files! Save it as
text (“.txt”) or as PDF (“.pdf”) and turn that in
- All Python source code files must end in “.py”
- Do your program in a file, not in the Python shell, unless
specifically told to
- The index variable in a loop is a counter; if you can use it in
the loop, great, but you don’t have to (and often do not)
- Data types: numbers
- Integers and floating point numbers
- Show bits, words
- Math library
- Making library available to program: “import math”
- Functions: sqrt(), exp(), trigonometric, ceil(), floor(), pi, e
- With above form of inclusion, must prefix with “math.”
- With “from math import *”, don’t need “math.”
- Program to solve quadratic equation (see quad.py)
- Show for x2 + 2x + 1
- Show for x2 + 2x + 2