Advertisement
brendan-stanford

Multiple-choice_basic

Dec 13th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #import libraries
  2. from random import randint
  3.  
  4. #list of questions and corresponding answers
  5. questions = ["2+2=?", "3-1=?", "4x3=?", "12/2=?"]
  6. options=["A) 4", "B) 2", "C) 12", "D) 6"]
  7. results=["A", "B", "C", "D"]
  8.  
  9. #quesion function that chooses questions from list, presents possible answers and stores correct answer
  10. def question_list(q):
  11. print(questions[q])
  12. print(options)
  13. result=results[q]
  14. questions.pop(q)
  15. results.pop(q)
  16. return result
  17.  
  18. #game function randomly chooses a value from 0-3, and function calls question_quiz to select corresponding questions and answers to test user
  19. def quiz():
  20. print("Choose the correct letter!")
  21. score = 0
  22. limit = 3
  23. for i in range(3):
  24. q = randint(0, limit)
  25. result = question_list(q)
  26. choice = input("A, B, C, or D : ")
  27. #conditional checks whether user choice matches selected answer in question_list
  28. if choice == result:
  29. print("Correct")
  30. score += 1
  31. else:
  32. print("Incorrect")
  33. limit -= 1
  34. print("Final score: " + str(score))
  35.  
  36. #quiz function called
  37. quiz()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement