while i < len(numList): result = result + numList[i]or scan directly over the the list elements themselves:
for n in numList result = result + nWhile we didn't take off points, the second one exhibits better style: There's no reason to explicitly introduce the counter i if you're not interested in the specific positions of elements in the list. Actually, for style, list comprehension or map and reduce is better than either: there's no need to write an explicit loop here. Of course, you can also sum a list without using a loop at all by writing
sum(list)
[x for x in list]which just gives you x.
if senseAhead(sensorValues) == TrueWe didn't take off points, but it's better to write
if senseAhead(sensorValues)Remember that in Python, the == comparison returns a value that can be tested directly by if. There's no need to explicitly compare it with True or False.
while senseAhead(sensorValues) ...rather than
if senseAhead(sensorValues) ...While we didn't take points off, this might indicate a serious conceptual error about how SoaR brains work. In a brain, the job of the step procedure is to test the sensors, think, and issue a single motor command. The SoaR system then arranges for that step to be run over and over. This is the transducer model for programming embedded systems, as described in the course notes. The step procedure itself should not sit in a testing loop. Several people ran into this problem in doing the lab, when their robot seemed to be unresponsive.