Description
This quiz was built with Python. I made a function and variables for questions and correct answers, then repeated for every question and prompt for answer I had. It ends by giving the user the score they earned.
# Imports
import getpass, sys
# Function for questions
def question_with_response(prompt):
print("Question: " + prompt)
msg = input()
return msg
# Default Variables
questionscount = 3
correct = 0
# Starting outputs for user
print('Hello, ' + getpass.getuser() + " running " + sys.executable)
print("You will be asked " + str(questionscount) + " questions.")
print("Are you ready to take a test?")
# Lists for questions/answers
questions = ["Who is the starting QB for the Steelers?",
"Who is the HC for the Steelers?",
"How many Super Bowls have the Steelers won?"]
answers = ["Kenny Pickett",
"Mike Tomlin",
"Six"]
# For loop to loop through every question and update the correct variable
for x in range(questionscount):
rsp = question_with_response(questions[x])
if rsp == answers[x]:
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
# Give user result
print(getpass.getuser() + " you scored " + str(correct) +"/" + str(questionscount))
Hello, eshaan running /bin/python
You will be asked 3 questions.
Are you ready to take a test?
Question: Who is the starting QB for the Steelers?
Kenny Pickett is correct!
Question: Who is the HC for the Steelers?
Mike Tomlin is correct!
Question: How many Super Bowls have the Steelers won?
Six is correct!
eshaan you scored 3/3