Dark Mode On/Off
PUBLISHED ON: MARCH 14, 2022

# Quiz Application Python Project

Hello everyone, today we're going to make a fun Python quiz game.

## What is the Mechanism Behind it?

Our quiz game will offer the player questions to which the player must respond with the correct answer. Each question will be attempted three times. If the player does not correctly answer the question after three tries, the game will go to the next question and the player will earn no points. However, if the player correctly answers the question, he will get one point. The total points scored by the player are shown at the conclusion of the game.

## Setup of the Quiz Application Python Project

We'll need some questions and answers for our game before we start creating it.

### Here how it looks:

``````quiz = {
1 : {
"question" : "What is the first name of Iron Man?",
},
2 : {
"question" : "Who is called the god of lightning in Avengers?",
},
3 : {
"question" : "Who carries a shield of American flag theme in Avengers?",
},
4 : {
"question" : "Which avenger is green in color?",
},
5 : {
"question" : "Which avenger can change it's size?",
},
6 : {
"question" : "Which Avenger is red in color and has mind stone?",
}
}``````

In our situation, we'll employ some simple superhero-related questions.

Feel free to make up your own game questions and answers. Our questions and responses will be saved as a python dictionary in a separate python file.

Let's get started coding now.

## Source Code for Quiz Application Python Project

``````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.
"""
return True
else:
print(f"Wrong Answer :( \nYou have {attempts - 1} left! \nTry again...")
return False

def print_dictionary():

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("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') : ")
break
check = check_ans(question, answer, attempts, score)
if check:
score += 1
break
attempts -= 1

break