Simple Programming

Setting preferences—fonts, font size, indentation, autosave

Variations on the Chaos program: 20 times, prompt # of times, two column, labeled column
range()

Function names line main() in file.

Input ==> Process ==> Output model for coding

Think about what is required to do a calculation and what is produced.
Think about how you would solve the problem manually, with pencil and paper.
Although it sounds like new-age clap-trap, "try to be the computer".

Difference between input() and raw_input() and the difference between strings and numbers. Be sure to use good promts when writing interactive code.

Note the difference between strings and printing strings:

>>> test = "x\nx"
>>> test
'x\nx'
>>> print test
x
x

Difference between print and return. return allows results to be used in other calculations. print allows labeling and formatting. Both can be used with care.

Note nesting of functions: return loss(calories(distance, weight)) in walkItOff().

Demo code from class. Right click and select Save As to download to your computer.

Homework

1. The average person takes about 2000 steps to walk a mile. Write a function steps() to return the number of miles walked when called with the number of steps taken. I. e., steps(5000) would return 2.5. Be careful to avoid integer truncation!

2. Using the code from class as a starting point, write myCalories() and myIWalkItOff(), new versions of calories() and iWalkItOff(), that use steps() so input is the number of steps taken rather than the number of miles walked.

Turn in a printout of the code for each.