Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import libraries
- from random import randint
- #list of questions and corresponding answers
- questions = ["2+2=?", "3-1=?", "4x3=?", "12/2=?"]
- options=["A) 4", "B) 2", "C) 12", "D) 6"]
- results=["A", "B", "C", "D"]
- #quesion function that chooses questions from list, presents possible answers and stores correct answer
- def question_list(q):
- print(questions[q])
- print(options)
- result=results[q]
- questions.pop(q)
- results.pop(q)
- return result
- #game function randomly chooses a value from 0-3, and function calls question_quiz to select corresponding questions and answers to test user
- def quiz():
- print("Choose the correct letter!")
- score = 0
- limit = 3
- for i in range(3):
- q = randint(0, limit)
- result = question_list(q)
- choice = input("A, B, C, or D : ")
- #conditional checks whether user choice matches selected answer in question_list
- if choice == result:
- print("Correct")
- score += 1
- else:
- print("Incorrect")
- limit -= 1
- print("Final score: " + str(score))
- #quiz function called
- quiz()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement