Advertisement
defbind_

Multiple choice code

Aug 20th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. # Imported code is in the multiline comment
  2. """"
  3. class Question:
  4.    def __init__(self, body, answer):
  5.        self.body = body
  6.        self.answer = answer
  7. """
  8.  
  9. from Classes import Question
  10.  
  11. questions = [
  12.     "What is Alex's favourite color? \n(a) Black\n(b) Blue\n(c) Purple  ",
  13.     "What is Olga's favourite movie? \n(a) Home Alone\n(b) Shrek\n(c) Deadpool  ",
  14.     "what is Obama's last name? \n(a) Hillary\n(b) Obama\n(c) Michelle  "
  15. ]
  16. questions = [
  17.     Question(questions[0], "a"),
  18.     Question(questions[1], "b"),
  19.     Question(questions[2], "b"),
  20. ]
  21. def function(questions):
  22.     score = 0
  23.     for question in questions:
  24.         answer = input(question.body)
  25.         if answer == question.answer:
  26.             score += 1
  27.     print("You got " + str(score) + " / " + str(len(questions)))
  28. function(questions)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement