Outline for January 9

Reading: §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
  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: compute pay with overtime

Matt Bishop
Department of Computer Science
University of California at Davis
Davis, CA 95616-8562 USA
Last modified: Version of January 9, 2019 at 5:10PM
Winter Quarter 2019
You can get a PDF version of this