# [Tutor] Help with simple program using while loops and lists

sudhir chauhan sudhirchauhan1@yahoo.co.in
Sat Apr 12 12:47:01 2003

```Hi ,
not modify anything except commenting one line. this
will make it work at least :)
regards,
sudhir

## This program runs a test of knowledge

# First get the test questions
# Later this will be modified to use file io.
def j_questions():
return [["What color is the daytime sky on a clear
day?"],\
["What is the answer to life, the universe
and everything\n"],\
["What is a three letter word for mouse
trap?"]]

def get_questions():
if menu_item == 1 or 2:
#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"]]
else:
return

#This will test a single question
# it takes a single question in
#it returns true if the user typed the correct answer,
othrewise false

#extract the question and the answer from the list
#give the question to the user
print "Correct!!"
return true
else:
return false
# 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_questions(questions[index]):
right = right + 1
#Go to the next question
index = index + 1
#Notice the order of the computation, first
multiply, the divide
print "You got",right*100/len(questions),"%
right out of",len(questions)

#now lests run the questions

true = 1
false = 00
list = []

print '---------------------------'
print '1. Take the test?'
print '2. View the questions, and the answer.'
print '3. Quit the program. '
current = 0
if len(list) > 0:
while current < len(list):
print current,'. ',list[current]
current = current + 1
print "Ok here we go"
break
run_test(get_questions())
break
else: