[Tutor] Lists within lists return

Eve Kotyk e.kotyk@shaw.ca
Tue, 11 Dec 2001 15:37:05 +0000


 
> I don't like wildly guessing though, since its often very ineffective.
Agreed.


I resolved the problem:

There were two incorrect items:

1)  As you mentioned the function call run_test(get_questions()) was
indented too far.

2)  The other one was tricker.  It involved the 3 return lines in the
list in the first definition.  These lines needed to line up and mine
where originally not lined up.  See below:


# New version that works
# This program runs a test of knowledge

true = 1
false = 0

#First get the test questions
#Later this will be modified to use file io.
def get_questions():
    #notice how the data is stored as a list of lists 
    return [["What color is the daytime sky on a clear day? ","blue"],\
    	    ["What is the answer to life, the universe and everything? ",
"42"],\
    	    ["What is a three letter word for mouse trap? ","cat"]]


# Old version that doesn't work.
#this program runs a test of knowledge

true = 1
false = 0

#first get the test question
#later this will be modified to use file io
def get_questions():
    #notice how the data is stored in a list of lists
    return (["What colour is the daytime sky on a clear day? ","blue"]\
    	["What is the answer to life, the universe and everything?", "42"]\
    	["What is a three letter word for a mouse trap?", "cat"])
	    

Notice the square bracket of the above 3 lines do not line up.  This
seems like a weird thing.  I'm using Idle as my test editor and a line
break after the first statement dropped the next line down under
'return'.  One tab over wasn't far enough and two tabs over was too
far.  I finally settle for a combination of one tab and four spaces

E
    
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 

ekotyk

http://members.shaw.ca/e.kotyk/virtualstudio.htm