Python Quiz Post
Making a quiz using python.
import getpass, sys
def question_with_response(prompt):
print("Question: " + prompt)
msg = input()
return msg
questions = 3
correct = 0
print('Hello, ' + getpass.getuser() + " running " + sys.executable)
print("You will be asked " + str(questions) + " questions.")
question_with_response("Are you ready to take a test?")
rsp = question_with_response("What command is used to include other functions that were previously developed?")
if rsp == "import":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
rsp = question_with_response("What command is used to evaluate correct or incorrect response in this example?")
if rsp == "if":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
rsp = question_with_response("Each 'if' command contains an '_________' to determine a true or false condition?")
if rsp == "expression":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
print(getpass.getuser() + " you scored " + str(correct) +"/" + str(questions))
def Python_Quiz(prompt):
global word
print ("Question: " + prompt)
word = input()
return word
questions = 5
correct_answer = 0
print("Hello, you will be asked " + str(questions) + " short questions")
question_list = ["What is the answer to this math problem: What does 45x7=", "What is the most popular religion in the world?",
"What is the capital of the U.S?", "How many kg is in 5g", "How many mm are in 1 km"]
answer_list = ["315", "Christianity", "Washington D.C.", "0.005 kg", "1000000 mm"]
for i in range(5):
Python_Quiz(question_list[i])
if word == answer_list[i]:
print("Answer is correct")
correct_answer += 1
else:
print("Answer is incorrect")
print("You scored " + str(correct_answer) + "/" + str(questions))