Class 2

From Lupyan Lab
Jump to: navigation, search


  1. Going over solution to the parts of Exercise 1; discussion of trouble spots
  2. More on flow control
    1. breaking out of a loop
  3. Lists
    1. Initializing a list
    2. Adding an element to a list
    3. Iterating through lists
    4. Accessing individual elements in a list
    5. The [-1] shortcut
    6. The len operator
    7. Finding values: the in and not in operators
    8. Modifying lists: The values/reference distinction
  4. List exercise 1
    1. Given the list myList = ['one', 'two','three','four'], write code that will print the following:
    'one and a two and a three and a four'
  5. List exercise 2
    1. Copy the code below into canopy and execute it. It will create a list randomNums that contains 100 numbers in the range of 1-1000. [*]
      import random
      randomNums = [random.randrange(1,1001) for x in range(100)]
      Write code that finds the largest number in randomNums by iterating through it.
      Check your answer by comparing it to max(randomNums)
      Re-execute the code assigning values to randomNums and try it again to make sure that your code and max(randomNums) always gives the same answer.
    2. How to find where that number is located in the list.
  6. Showing text using the visual.textStim PsychoPy object
  7. File operations
    1. Reading from a file
    2. Writing to a file
  8. Basic string operations: split and join
  9. PsychoPy timers.
  10. Popping up a box to accept input

[*] This is an example of what's called list comprehension. We'll cover it later in the term.

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