Python Programming Lecture 2, Fall 2009

http://grace.evergreen.edu/mon/asn-python.html

Software Development - Ch 2.1

  1. Analyze the problem - understand the problem
  2. Specify what your program will do, inputs, outputs, and words to say what the transformation is from input to output.
  3. 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.
  4. Implement your design in Python code.
  5. Test and Debug your program.
  6. Maintain the program as it is needed over the years.

Celsius to Fahrenheit temperature converter - Ch 2.2

  1. The input-process-output (IPO) design pattern
  2. The algorithm
  3. celsiusToFahr.py - The temperature convert program
  4. Notice the use of variables as temporary storage areas and the = symbol as signifying assignment instead of equality!
  5. Programming variables are not the same as mathematical variables!.
  6. Important: Equality in programming is == not =

Elements of Programs - Ch 2.3

  1. Names, aka, identifiers (see p29).
  2. Reserved words. See Appendix A p469
  3. Expressions are pretty much just like mathematical expressions
  4. NameError - using a name that hasn't been given a value or definition.
  5. Various print statements (see examples p32).
  6. Types of values used in expressions
  7. Note that "celsius" is a string value but celsius is a variable

  8. All variables and expressions have types
  9. Operations depend on types - 9 / 5 is different than 9.0 / 5.0
  10. 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

  1. Variables are named storage boxes that can assigned values and be overwritten with new values.
  2. The = symbol is used (unfortunately) for assignment not equality
  3. A variable is always on the left side of an assignment statement
  4. Python allows multiple simultaneous assignment (see p36-39).
  5. Notice the handy way to get multiple inputs in one prompt (see p38).

Definite Loops - Ch 2.6

  1. The definite loop schema uses the keywords for and in
          for < var > in < sequence >:
            < body >
        
  2. Indentation is critical. The loop body is a sequence of python code statements
  3. The loop body gets executed as many times as the sequence is long
  4. 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.
  5. Examples p40 using definite sequence [1,3,5,7,9]
  6. Example of definite loop called a counted loop using range(10) (p40)
  7. 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

  1. Use a formula (the theoretical approach in Kalman)
  2. Or use an iterative method (the difference equation method in Kalman)