It is very annoying, I have typed it as best I can, but option 2 doesn't work. Option 1 is to take the test in Test.py, option 9 is to quit, and option 2 is supposed to print all the questions and answers. This is the code:
true = 1
false = 0
def get_questions():
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 mouse trap?","cat"],\
["What noise does a truly advanced machine make?","ping"]]
menu_item = 0
while menu_item != 9:
print "------------------------------------"
print "1. Take test"
print "2. Display all questions and answers."
print "9. quit"
menu_item = input("Pick an item from the menu: ")
if menu_item == 1:
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 "Correct"
return true
else:
print "Incorrect, correct was: ",answer
return false
def run_test(questions):
if len(questions) == 0:
print "No questions were given."
return
index = 0
right = 0
while index < len(questions):
if check_question(questions[index]):
right = right + 1
index = index + 1
print "You got ",right*100/len(questions),"% right out of",len(questions)
run_test(get_questions())
elif menu_item == 2:
current = 0
if len(get_questions) > current:
while current < len(get_questions(index)):
index=current
print current,". ",get_questions(current)
current = current + 1
else:
print "No questions"
print "Goodbye."
Here is the error message when I type "2" into the option selection:
Traceback (most recent call last):
File "C:\Python24\test", line 45, in -toplevel-
print current,". ",get_questions(current)
TypeError: get_questions() takes no arguments (1 given)
What is wrong with my program and how do I fix it?