Some mistakes students commonly make

  1. Say data is a list. When you write  for r in data:, r is a reference to the contents of data. You cannot use r to index the list, like data[r]. 
  2. If you want to use r to index the list data, use the construct for r in range(len(data)) .Now r assumes values in the range 0..len(data)-1.
  3. ^ is not the exponentiation operator in Python. ^ is the bitwise xor (exclusive or) operator. Evaluate  3^2 in the interpreter to see what it does.
  4. Variables referenced as self.variableName are instance variables in a Python class, and have class-wide scope. If you leave out the self, variableName by itself is merely a local variable within the method.