Python Quiz

This quiz was created using python. It asks 5 questions related to python and other topics learned in CSP. At the end of the quiz, it calculates the score as a percentage.

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
Hello, davidv running /bin/python3
You will be asked 5 questions.
Question: Are you ready to take a test?
Lets Start!
Question: What command is used to include other functions that were previously developed?
import is correct!
Question: What command is used to evaluate correct or incorrect response in this example?
if is correct!
Question: Each 'if' command contains an '_________' to determine a true or false condition?
expression is correct!
Question: What are words surrounded by quotation marks called?
strings is correct!
Question: What tab in Github is used to monitor the status of the changes you push?
actions is correct!
davidv you scored 5/5 or 100.0%