Outline for January 25
Reading: text, §3.2, 4.14, 12
Due: Homework 2, due on February 1 at 11:55pm
- Conditions
- Resolves to boolean value
- Literal booleans: True (1), False (0)
- Relational operators
- Use two arithmetic expressions connected with relational operators to create a boolean
- Relational operators: >, >=, <, <=, ==, !=
- Precedence: resolved after arithmetic operators
- Connectives: and, or, not
- 6 > 2 + 3; "UCD" == "Sac State"
- Indefinite loops: execute until a general condition is false (while)
- while [while.py]
- Contrast with for
- break causes program to fall out of loop (works with for too) [loop1.py]
- continue causes program to start loop over immediately (works with for too) [loop1.py]
- Definite loops: execute a specific (definite) number of times (for)
- General form: for i in iterator
- Iterator is either list or something that generates a list
- Very common form: for i in range(1, 10)
- range() in detail [for.py]
- range(10) gives 0 1 2 3 4 5 6 7 8 9
- range(3, 10) gives 3 4 5 6 7 8 9
- range(2, 10, 3) gives 2 5 8
- range(10, 2, -3) gives 10 7 4
- Handling exceptions
- except [except0.py]
- except error [except1.py]
- else [except2.py]
- except error as msgvar [except3.py]
- finally [except4.py]
- Exceptions in a function: who handles them? [except5.py, except6.py]