Skip to content

Update Quiz Game.py #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 39 additions & 54 deletions Quiz Game/Quiz Game.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,41 @@
from questions import quiz


def check_ans(question, ans, attempts, score):
"""
Takes the arguments, and confirms if the answer provided by user is correct.
Converts all answers to lower case to make sure the quiz is not case sensitive.
"""
if quiz[question]['answer'].lower() == ans.lower():
print(f"Correct Answer! \nYour score is {score + 1}!")
return True
else:
print(f"Wrong Answer :( \nYou have {attempts - 1} left! \nTry again...")
return False


def print_dictionary():
for question_id, ques_answer in quiz.items():
for key in ques_answer:
print(key + ':', ques_answer[key])


def intro_message():
"""
Introduces user to the quiz and rules, and takes an input from customer to start the quiz.
Returns true regardless of any key pressed.
"""
print("Welcome to this fun food quiz! \nAre you ready to test your knowledge about food?")
print("There are a total of 20 questions, you can skip a question anytime by typing 'skip'")
input("Press any key to start the fun ;) ")
return True


# python project.py
intro = intro_message()
while True:
score = 0
for question in quiz:
attempts = 3
while attempts > 0:
print(quiz[question]['question'])
answer = input("Enter Answer (To move to the next question, type 'skip') : ")
if answer == "skip":
break
check = check_ans(question, answer, attempts, score)
if check:
score += 1
break
attempts -= 1

break

print(f"Your final score is {score}!\n\n")
print("Want to know the correct answers? Please see them below! ;)\n")
print_dictionary()
print("Thanks for playing! 💜")
score = 0
skipped_questions = set()

print("Welcome to this fun food quiz!")
print("Are you ready to test your knowledge about food?")
print("There are a total of 20 questions. You can skip a question anytime by typing 'skip'.")
input("Press any key to start the fun ;) ")

for question in quiz:
attempts = 3
while attempts > 0:
print(quiz[question]['question'])
answer = input("Enter Answer (To move to the next question, type 'skip'): ")

if answer == "skip":
skipped_questions.add(question)
break

if quiz[question]['answer'].lower() == answer.lower():
score += 1
break

attempts -= 1
print(f"Wrong Answer :( \nYou have {attempts} attempt(s) left! \nTry again...")

print(f"\nYour final score is {score}!\n")

print("Skipped questions:")
for question_id in skipped_questions:
print(quiz[question_id]['question'])
print("\n")

print("Correct answers:")
for question_id, ques_answer in quiz.items():
print(f"Question: {ques_answer['question']}")
print(f"Answer: {ques_answer['answer']}")
print()

print("\nThanks for playing! 💜")