Commit 36bf6116 authored by Niyas Inshaf's avatar Niyas Inshaf

Add new file

parent b34e01b0
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()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment