Python Quiz
A quiz created using Python.
import getpass, sys
def question_with_response(prompt): #defines question_and_response
print("Question: " + prompt) #prompts the user with the phrase "Question:" and the question
msg = input() #takes the input of the user
return msg #returns string value
questions = 5 #total number of questions asked
correct = 0 #default number of questions correct
print('Hello, ' + getpass.getuser() + " running " + sys.executable) #prints the greeting of the test
print("You will be asked " + str(questions) + " questions.") #prints the amount of questions that are going to be asked
rsp = question_with_response("Are you ready to take a test?") #asks for user input before starting the test
if rsp == "yes": #compares the user's input to the correct answer, which is "import"
print("Lets Start!") #if the answer is correct, this runs
else: #goes to this if the answer does not equal the correct answer
print(rsp + " is incorrect!") #if the answer is incorrect, this runs
rsp = question_with_response("What command is used to include other functions that were previously developed?") #question is asked
if rsp == "import": #compares the user's input to the correct answer, which is "import"
print(rsp + " is correct!") #if the answer is correct, this runs
correct += 1 #adds one to the number of correct answers
else: #goes to this if the answer does not equal the correct answer
print(rsp + " is incorrect!") #if the answer is incorrect, this runs
rsp = question_with_response("What command is used to evaluate correct or incorrect response in this example?") #question is asked
if rsp == "if": #compares the user's input to the correct answer, which is "if"
print(rsp + " is correct!") #if the answer is correct, this runs
correct += 1 #adds one to the number of correct answers
else: #goes to this if the answer does not equal the correct answer
print(rsp + " is incorrect!") #if the answer is incorrect, this runs
rsp = question_with_response("Each 'if' command contains an '_________' to determine a true or false condition?") #question is asked
if rsp == "expression": #compares the user's input to the correct answer, which is "expression"
print(rsp + " is correct!") #if the answer is correct, this runs
correct += 1 #adds one to the number of correct answers
else: #goes to this if the answer does not equal the correct answer
print(rsp + " is incorrect!") #if the answer is incorrect, this runs
rsp = question_with_response("What are words surrounded by quotation marks called?") #question is asked
if rsp == "strings": #compares the user's input to the correct answer, which is "wsl"
print(rsp + " is correct!") #if the answer is correct, this runs
correct += 1 #adds one to the number of correct answers
else: #goes to this if the answer does not equal the correct answer
print(rsp + " is incorrect!") #if the answer is incorrect, this runs
rsp = question_with_response("What tab in Github is used to monitor the status of the changes you push?") #question is asked
if rsp == "actions": #compares the user's input to the correct answer, which is "actions"
print(rsp + " is correct!") #if the answer is correct, this runs
correct += 1 #adds one to the number of correct answers
else: #goes to this if the answer does not equal the correct answer
print(rsp + " is incorrect!") #if the answer is incorrect, this runs
quotient = correct / questions #defines quotient
ptge = quotient * 100 #defines ptge
print(getpass.getuser() + " you scored " + str(correct) +"/" + str(questions) + " or " + str(ptge) + "%") #this prints the score that the user gets