[Tutor] help
Feziwe Mpondo
feziwe at sanbi.ac.za
Wed May 11 14:50:02 CEST 2005
hi
i'm trying to extend a list program by adding a test, problem is after
getting the menu of taking the test i can't seem to get the test running
i.e viewing of questions and answers. here's what i tried to do
menu_item = 0
list = []
while menu_item !=9:
print "---------------------"
print "1. print the questions"
print "2. take the test"
print "3. quit"
menu_item = input("pick an item from the menu: ")
if menu_item == 1:
current = 0
if len(list) > 0:
while current < len(list):
print current,".",list[current]
current = current > 0
else:
print "list is empty"
elif menu_item == 2:
current = raw_input("do you want to take a test: ")
list.append(list)
else:
print[["what is the third month of the year?" , "march"],
["who is the president of south africa" , "Thabo"],
["whos birthday is it today" , "Allank"],
["which day comes after a friday" , "saturday"]]
true = 0
false = 1
def get_questions():
return [["what is the third month of the year?" , "march"],
["who is the president of south africa" , "Thabo"],
["whos birthday is it today" , "Allank"],
["which day comes after a friday" , "saturday"]]
def check_question(question_and_answer):
question = question_and_answer[0]
answer = question_and_answer[1]
given_answer = raw_input(question)
if answer == given_answer:
print "Good"
return true
else:
print "incorrect, correct was:",answer
return false
def run_test(questions):
if len(questions) == 1:
print "No questions were given."
return
index = 0
right = 0
while index < len(questions):
if check_question(question[index]):
right = right + 1
index = index + 1
print "you got ",right*100/len(questions),"%right out of",len(questions)
run_test(get_questions)
More information about the Tutor
mailing list