Python Quiz Showcase
Using my python quiz
import getpass, sys
import random
# This creates the function that I'll be using to create the quiz
def question_and_answer(prompt):
print("Question: " + prompt)
msg = input()
print("Answer: " + msg)
def question_with_response(prompt):
print("Question: " + prompt)
msg = input()
return msg
# This creates the variables that will be used to calculate score
questions = 5
correct = 0
# Introduces user to quiz
print('Hello, ' + getpass.getuser() + " running " + sys.executable)
print("You will be asked " + str(questions) + " questions.")
question_and_answer("Are you ready to take a test?")
# Starts quiz
rsp = question_with_response("What is 9+9")
if rsp == "18":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
rsp = question_with_response("What is my favorite electronic device")
if rsp == "computer":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
rsp = question_with_response("Do you have any pets?")
if rsp == "Yes":
print("Yes? That's nice!")
correct += 1
else:
print("hrm, cool")
correct += 1
rsp = question_with_response("Is this a fun quiz?")
if rsp == "no":
print(rsp + " is correct!")
correct += 1
else:
print("herm")
correct += 1
rsp = question_with_response("I'll let you go free now, are you enthused?")
if rsp == "Yes":
print("hee, rude")
correct += 1
else:
print("welp")
correct += 1
# Tells user their score
print(getpass.getuser() + " you scored " + str(correct) +"/" + str(questions))