Here is my code. It is a quick 10-question quiz on basic python knowledge!

Quiz Version 1

This is my first version of my quiz, where I only wrote one function to print out the question with the prompt and get the user's input. For each question, I then evaluated if it was correct (so 10 times in total because 10 questions). This is pretty tedious because I was rewriting a lot of code each time.

import getpass, sys

def question_with_response(prompt):
    msg = input("Question: " + prompt)
    return msg

# Numer of questions
questions = 10

# Number of correct questions
correct = 0

# Setup
name = input("What is your name? ")
print("Hello " + name + ". You will be asked " + str(questions) + " questions about Python. Please type all your answers lowercase!")
print("Test starting...")

# These are the questions, also testing if the answer is correct or not
rsp = question_with_response("1. 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("2. 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("3. 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!")

rsp = question_with_response("4. What command is used to display contents to the screen?")
if rsp == "print":
    print(rsp + " is correct!")
    correct += 1
else:
    print(rsp + " is incorrect!")

rsp = question_with_response("5. If you want to store a number in something, but you also want to be able to change it later, what would you store it in?")
if rsp == "variable":
    print(rsp + " is correct!")
    correct += 1
else:
    print(rsp + " is incorrect!")

rsp = question_with_response("6. What command is used to get input from the user?")
if rsp == "input":
    print(rsp + " is correct!")
    correct += 1
else:
    print(rsp + " is incorrect!")

rsp = question_with_response("7. What keyword is used to define a function?")
if rsp == "def":
    print(rsp + " is correct!")
    correct += 1
else:
    print(rsp + " is incorrect!")

rsp = question_with_response("8. Can functions take parameters (yes/no)?")
if rsp == "yes":
    print(rsp + " is correct!")
    correct += 1
else:
    print(rsp + " is incorrect!")

rsp = question_with_response("9. What language are we learning?")
if rsp == "python":
    print(rsp + " is correct!")
    correct += 1
else:
    print(rsp + " is incorrect!")

rsp = question_with_response("10. What is the formal term for combining multiple strings together? (two words)")
if rsp == "string concatenation":
    print(rsp + " is correct!")
    correct += 1
else:
    print(rsp + " is incorrect!")

print(name + ", you scored " + str(correct) +"/" + str(questions))
print("Your percentage is " + str(correct/questions*100) + "%! Good work!")
Hello Sophia. You will be asked 10 questions about Python. Please type all your answers lowercase!
Test starting...
import is correct!
if is correct!
expression is correct!
print is correct!
variable is correct!
input is correct!
def is correct!
yes is correct!
python is correct!
string concatenation is correct!
Sophia, you scored 10/10
Your percentage is 100.0%! Good work!

Quiz Version 2

In this second version of my quiz, I created a function that takes in the prompt and the answer, get's the user input, and then returns 1 if the user got it correct and 0 is the user got it incorrect. This way, I only had to make two lists (one of questions and one of answers). I iterated through all the questions and answers using a for looso my code was much simpler, neater, and much more concise as well.

You can see this implementation below! :D

import getpass, sys

def question(prompt, answer):
    msg = input("Question: " + prompt)
    if msg == answer:
        print(msg + " is correct!")
        return(1)
    else:
        print(msg + " is incorrect!")
        return(0)

questions = ["1. What command is used to include other functions that were previously developed?", "2. What command is used to evaluate correct or incorrect response in this example?", "3. Each 'if' command contains an '_________' to determine a true or false condition?", "4. What command is used to display contents to the screen?", "5. If you want to store a number in something, but you also want to be able to change it later, what would you store it in?", "6. What command is used to get input from the user?", "7. What keyword is used to define a function?", "8. Can functions take parameters (yes/no)?", "9. What language are we learning?", "10. What is the formal term for combining multiple strings together? (two words)"]
answers = ["import", "if", "expression", "print", "variable", "input", "def", "yes", "python", "string concatenation"]

# Numer of questions
numqs = 10

# Number of correct questions
correct = 0

# Setup
name = input("What is your name? ")
print("Hello " + name + ". You will be asked " + str(numqs) + " questions about Python. Please type all your answers lowercase!")
print("Test starting...")

for i in range(0, 10):
    num = question(questions[i], answers[i])
    correct = correct + num

print(name + ", you scored " + str(correct) +"/" + str(numqs))
print("Your percentage is " + str(correct/numqs*100) + "%! Good work!")
Hello Sopha. You will be asked 10 questions about Python. Please type all your answers lowercase!
Test starting...
import is correct!
if is correct!
expression is correct!
print is correct!
variable is correct!
input is correct!
def is correct!
yes is correct!
python is correct!
string concatenation is correct!
Sopha, you scored 10/10
Your percentage is 100.0%! Good work!