Outline for January 9

Reading: Wentworth et al., §2
Due: Homework 1, due on January 18 at 11:55pm


  1. Variables
    1. What they are
    2. Variable names
    3. Variable types (int, float, string)
    4. Function type()
    5. Python keywords
  2. Variables
    1. Legal names
    2. Keywords
    3. How to pick variable names
  3. Simple assignment: variable = expression
  4. 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
  5. Example
    1. Compute the hypotenuse of a right triangle [hypotnoex.py]
  6. The difference between strings and integers [twoplustwo.py]
    1. Difference between '2 + 2', 2 + 2
    2. Print statements usually end lines
    3. Getting print statements not to end lines
  7. Type converter functions int, float, str
  8. String operators
    1. Operator +: string concatenation
    2. Operator *: repetition
  9. Input: input statement
    1. input(prompt) prints prompt, waits for user
    2. When user hits enter, it returns what was typed as a string
  10. Exceptions
    1. Division by zero [divby0.py]
    2. Typing letters when a number is expected [hypotex.py]
  11. Writing a program: rice on chessboard [ricechess.py]


UC Davis seal
Matt Bishop
Office: 2209 Watershed Science
Phone: +1 (530) 752-8060
Email: [email protected]
You can also obtain a PDF version of this.
Version of January 9, 2019 at 11:21AM