Outline for October 10, 2012
Reading
: § 6
Assignment Due
: October 12, 2012 at 5:00PM
Miscellaneous
Announce: you
must
use a function to compute the vapor pressure for homework problems 1 and 2!
Review local and global variables (basic rule: do
not
use globals)
range(-20, 51, 5)
vs.
range(50, -20, -5)
Simultaneous assignment [
swap.py
]
Simple assignment:
variable = expression
Simultaneous assignment:
variableA, variableB = expressionA, expressionB
Decision structures [
if0.py
]
If statement
Executes once, based on condition
Syntax
Conditions
Resolves to boolean value
Literal booleans:
True
(1),
False
(0)
Testable as true or false
Relational operators
Use two arithmetic expressions connected with relational operatorsto create a boolean
Relational operators:
>
,
>=
,
<
,
<=
,
==
,
!=
Precedence: resolved after arithmetic operators
6 > 2 + 3
;
"UCD" == "Sac State"
Two-way decisions [
if1.py
]
if-else statements
One condition, two possible code blocks
Syntax
else very powerful when the positive condition is easy to describe but not the negative
String comparison example
Multi-way decisions [
if2.py
]
Can execute code based on several conditions
elif
(
else if
)
Syntax
else only reached if all previous conditions false
Nested if statements
A PDF version is available here.
ECS 10, Basic Concepts of Computing
Fall Quarter 2012