Advertisement
VergeoPaw

51_QNA

Sep 20th, 2021
654
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. def get_question() :
  2.     questionBank = [
  3.         ["What color is the daytime sky on a clear day?", "blue"],
  4.         ["What is the answer to life, the universe and everything?", "42"],
  5.         ["What is a three letter word for mouse trap?", "cat"],
  6.         ["What is always in front of you but can’t be seen?", "future"]
  7.         ["What is full of holes but still holds water?", "sponge"],
  8.         ["What gets wet while drying?", "towel"]
  9.     ]
  10.     return questionBank
  11.  
  12. def check_question(row) :
  13.     q = row[0]
  14.     a = row[1]
  15.     user_a = input(q)
  16.     if user_a == a :
  17.         print("Correct!")
  18.         return True
  19.     else :
  20.         print(f"Incorrect! The correct answer was {a}")
  21.         return False
  22.  
  23. def main(questionBank) :
  24.     if len(questionBank) == 0 :
  25.         print("No question were given")
  26.         return 0
  27.  
  28.     index = 0
  29.     right = 0
  30.     while index < len(questionBank) :
  31.         # print(questionBank[index])
  32.  
  33.         result = check_question(questionBank[index])
  34.         if result :
  35.             right +=1
  36.  
  37.         index +=1
  38.     print(f"your score is {right/len(questionBank)*100}")
  39.  
  40. main(get_question())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement