Outline for October 8, 2012
Reading
: § 4
Assignment Due
: October 12, 2012 at 5:00PM
Iteration
Definite loops: execute a specific (definite) number of times
Indefinite loops: execute until a general condition is false
For loops
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
Program: counting to 10 [
toten.py
]
Program: sum the first 10 squares [
sumsq.py
]
Program: Fibonacci numbers [
fib.py
]
Decision structures
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"
A PDF version is available here.
ECS 10, Basic Concepts of Computing
Fall Quarter 2012