[Tutor] Lists within lists return

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Mon, 10 Dec 2001 18:26:39 -0800 (PST)


On Tue, 11 Dec 2001, Eve Kotyk wrote:

> I'm working through the Josh Cogliati tutorial on the Python site.  In
> the secton on lists, example 8.3, test.py is given along with a sample
> output.  I've typed up the program using Idle but I do not get the
> expected output.  In fact I get no output at all and I don't get any
> error messages.  Below see the example code as cut and pasted from my
> file.  I would appreciate any help you might be able to give me.

I think this is the culprit: the last half of your program, starting from
this line:

>     #This will run through all the questions
>     def run_test(questions):
>         if len(questions) == 0:
>             print "No questions were given."
>             #the return exits the function
>             return
>         index = 0
>         right = 0
>         while index < len(questions):
>             #Check the question
>             if check_question(questions[index]):
>                 right = right + 1
>                 #go to the next question
>                 index = index + 1
>         #notice the order of the computation, first multiply, then
> divide
>         print "you got ",right*100/len(questions), "% right out of",\ 		
> len(questions)
>     #now lets run the questions
>     run_test(get_questions())

is indented too far.  You probably want the definition of run_test() to be
outside check_question().

If you bring the indentation level down one level for these lines, you
should be ok.  Hope this helps!