ECS 10, Basic Concepts of Computing Spring Quarter 2009
Version of April 2, 2009 at 4:47 PM Page 1 of 1
Outline for April 29, 2009
Reading: text, §7.1–7.3 Guest Lecturer: Justin Cummins
1. Decision structures
a. If statement
b. Executes once, based on condition
c. Syntax (added condition to superkondit.py)
2. Conditions
a. Resolves to boolean value
b. Literal booleans: True, False
c. Testable as true or false
d. Relational operators (extended condition in superkondit.py)
i. Use two arithmetic expressions to create a boolean
ii. >, >=, <, <=, ==, !=
iii. Resolved after arithmetic operators
iv. 6 > 2; "UCD" == "Sac State"
v. Python allows all sorts of comparison (even confusing ones)
3. Two-way decisions
a. If-else statements
b. One condition, two possible code blocks
c. Syntax (extended superkondit.py)
d. Else very powerful when the positive condition is easy to describe but not the
negative
e. String comparison example (see bad_login.py)
4. Multi-way decisions
a. Can execute code based on several conditions
b. elif (else if) introduced
c. Syntax (extended superkondit.py)
d. elif only reached if all previous conditions false