Specify what your program will do, inputs, outputs, and words
to say what the transformation is from input to output.
Design how you will perform the specified transformation. This
is usually algorithms and data structures. Use words and pseudocode to say
how in a high-level and easily comprehensible way.
Implement your design in Python code.
Test and Debug your program.
Maintain the program as it is needed over the years.
Celsius to Fahrenheit temperature converter - Ch 2.2
The input-process-output (IPO) design pattern
The algorithm
prompt for a Celsius temperature and put it in a celsius variable called c
calculate the standard conversion and put the result in a variable called f
Output the fahrenheit variable f
celsiusToFahr.py - The temperature convert program
Notice the use of variables as temporary storage areas and the = symbol
as signifying assignment instead of equality!
Programming variables are not the same as mathematical
variables!.
Important: Equality in programming is == not =
Elements of Programs - Ch 2.3
Names, aka, identifiers (see p29).
Reserved words. See Appendix A p469
Expressions are pretty much just like mathematical expressions
NameError - using a name that hasn't been given a value or definition.
Various print statements (see examples p32).
Types of values used in expressions
Integers 7
Floating point numbers 7.0
Strings "hi there"
Note that "celsius" is a string value but celsius is a variable
All variables and expressions have types
Operations depend on types - 9 / 5 is different than 9.0 / 5.0
Python type conversion is automatic - 9.0 / 5 mixes types so python
automatically converts to the most inclusive type. 9.0 / 5 gets converted to
9.0 / 5.0 automatically. Not all languages do this auto-conversion and will
instead give an error.
Assignment Statements - Ch 2.5
Variables are named storage boxes that can assigned values and
be overwritten with new values.
The = symbol is used (unfortunately) for assignment not equality
A variable is always on the left side of an assignment statement
Python allows multiple simultaneous assignment (see p36-39).
x, y = 6, 7 is the same as x = 6 and y = 7 simultaneously.
x, y = y, x must be done in three sequential steps, why? (see p37).
Notice the handy way to get multiple inputs in one prompt (see p38).
Definite Loops - Ch 2.6
The definite loop schema uses the keywords for and in
for < var > in < sequence >:
< body >
Indentation is critical. The loop body is a sequence of python
code statements
The loop body gets executed as many times as the sequence is long
Each time through the loop, var, the loop index, is automatically
assigned next value in the sequence and can be used in the body of the loop.
Examples p40 using definite sequence [1,3,5,7,9]
Example of definite loop called a counted loop using range(10) (p40)
Definite loops always have and end. Later, indefinite loops using
the keyword while can potentially run forever. (See p476).
The future value program - Ch 2.7
Use a formula (the theoretical approach in Kalman)
Or use an iterative method (the difference equation method in Kalman)