Class 3

From Lupyan Lab
Jump to: navigation, search


  1. Going over Exercise 2
    1. further clarification of getKeys() and waitKeys()
    2. if, else, and elif
  2. Dictionaries
    1. Differences from lists; ordered vs unordered sequences
    2. Keys, values, iteration
  3. Dictionary exercise
    1. Use a dictionary to remove all the if statements from this code which shows squares in different positions on the screen.
    2. Now extend your solution to make the squares on top always be white, squares on the right, red, squares on the bottom, green, and squares on the left, yellow. Do not use any if statements.
    3. Solution to the dictionary exercises
  4. Functions
    1. What's a function and why do we want them?
    2. The return statement.
    3. Scope: what variables are visible/invisible to a function
    4. Ordered arguments vs. named arguments.
    5. Optional vs. required arguments
  5. Function-writing exercises
    1. Write a function findAll that takes two arguments: lst--a list-- and target--some value (integer, string) and returns all the indices of the list that contain that item. If the value is not in the list, it should return an empty list.
    2. Something a bit harder: write another function findMultipleTargets which accepts two lists as arguments -- lst and targets -- and return all the indices from lst of items from targets. For example, if lst is ['cat','dog','fish', 'fish', 'zebra'] and targets is ['zebra', 'fish'], the function should return [[4],[2,3]]. If targets are ['dog', 'panda'], the function should return [[1], []]
    3. Solution to findAll and findMultipleTargets
  6. Randomization
    1. Uses of random sequences
    2. The random library
      1. random.random(), random.choice, random.randrange(), random.sample()
      2. Shuffling lists in place with random.shuffle()
    3. What's a random number generator anyway?
      1. Controlling the random number generator using random.seed()
    4. Randomization and controlled randomness/counterbalancing.
Personal tools
Namespaces
Variants
Actions
Navigation
Download and Install
Notes for each class - will be updated ~week before each class.
Programming Exercises
Projects
Quick reference
Toolbox