0

I am working on a multiple choice quiz. I want to be able to give user a chance to pick a valid option (a, b, or c) in case they chose a non-existent one (e.g. e). How do I get this done? At the moment, it goes right to the next quiz.

Here's a portion of my code:

def ask_question(question,score):
    choices=('a','b','c')
    print(question[0])
    for multi in question[1:-1]:
        print("{0:>5}{1}".format("",multi))
while True: 
    answer = input("Please select an answer: ")
    if answer == question[-1] and answer in choices: 
        score += 1

    elif answer not in choices:
        print("Incorrect.Try again")
    break

def main():
    questions = get_questions()
    score = 0
    number = 10
    print("Welcome to first quiz!")
    print()

    for next_question in range(number):
        question = random.choice(questions)
        score = ask_question(question, score)
        questions.remove(question)
    print("Your final score was {0} out of {1}.".format(score,number))
    if score >= number * 0.75:
        print("You have passed.")
    else:
        print("You have failed.")
if __name__ == "__main__":
    main()
  • I'm a bit confused. Why do you define a function called ask_question when you don't seem to be calling it? – wwl Nov 10 '16 at 23:04
  • I am except the code is little long. If that helps, here it is(see edits above) – Joel Oduor Bwana Nov 10 '16 at 23:06
  • I don't understand why one marks question as duplicate disregarding the fact that people write codes differently. If the admin, or whoever does this think its a duplicate, they should at least tell user where to find the answer. – Joel Oduor Bwana Nov 10 '16 at 23:15

0 Answers0