Outline for October 3, 2012

Reading: § 2


  1. Simple assignment: variable = expression
  2. Expressions
    1. Operators +, -, *, /, //, %, **
    2. Precedence
      1. Parentheses for grouping ((, ))
      2. Exponentiation (**); associates right to left
      3. Positive, negative (unary +, -)
      4. Multiplication, division, integer division, remainder (*, /, //, %)
      5. Addition, subtraction (binary +, -)
      6. In general, operators of equal precedence are evaluated from the left to the right (associativity); exception noted above
  3. Input: input statement
    1. input(prompt) prints prompt, waits for user
    2. When user hits enter, it returns what was typed as a string
  4. Type converter functions int, float
  5. import statement
    1. import math
  6. Example: program to compute the length of the hypotenuse of a right triangle [hypotf.py]
    1. What is the math formula? (Pythagoras: )
    2. Steps in the program:
      1. Ask user for length of two other sides
      2. Compute hypotenuse, using math library’s square root function
      3. Print result
    3. Implementation (line by line)
  7. Another form of the import statement
    1. from math import sqrt [hypot.py]

A PDF version is available here.
ECS 10, Basic Concepts of Computing
Fall Quarter 2012