-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquiz_game.py
More file actions
44 lines (35 loc) · 1.13 KB
/
quiz_game.py
File metadata and controls
44 lines (35 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#Global variables
quiz_key = [
("What is the best color?", "Orange"),
("What is the best name?", "Tim"),
("Who are you?", "Me?"),
("Are you a computer?", "yes"),
("Did you answer these answers truthfully?", "No")
]
def quiz_question(question, answer):
question += " "
user_answer = input(question)
if user_answer.lower() == answer.lower():
print("Correct!")
return 1
else:
print("Incorrect.")
return 0
def main():
print("Welcome to my computer quiz!")
answer = input("Would you like to play a game? ")
if answer.lower() != "yes":
print(f"Expected \"yes\", received \"{answer}\".\nGoodbye")
quit()
print("Okay! Let's play!")
score = 0
for q_a in quiz_key:
question, answer = q_a
score += quiz_question(question, answer)
possible_score = len(quiz_key)
percent_score = (score / possible_score) * 100
print(f"\nYour total score was {score} out of {possible_score}.")
print(f"That's also known as {percent_score}%.")
print("\nThanks for taking my quiz!\nGoodbye :)\n")
if __name__ == "__main__":
main()