Outline for January 11, 2012
Reading:
§1
IDLE
How to use it
How to start, open a new window
Python shell, prompt
Example using IDLE: hello, world
Explain printing
Demonstrate program in IDLE
Second example: compute 2 + 2, properly labeled [
twoplustwo.py
]
Difference between
'2 + 2'
,
2 + 2
Print statements usually end lines
Getting print statements not to end lines
Exceptions [
divby0.py
]
Division by zero
How you handle it
Third example: chaos program, version 1 [
chaos1.py
]
Comments
Function
input()
gets input as a string from user
Function
float()
converts data to a floating point number
Assignment to variable; evaluate right hand side first
For loop in detail
Built-in
range()
function
Index variable
i
initialized to 0
Loops
Expression using multiplication, subtraction, and variables
Behavior with initial values of 0.25 and 0.26
Fourth example: chaos program, version 2, error handling [
chaos2.py
]
What if the user types in a non-number?
What if the user types in a bad number?
A PDF version is available here.
ECS 10, Basic Concepts of Computing
Winter Quarter 2012