Below, I used python to make a quiz. I first defined a function that prints the argument(question) given. I added some pre quiz questions to collect the name and if they are ready to take the quiz. After that, I used a for loop and enumerate function to use the corresponding questions and answers in my question function. Lastly, I used some math operations to calculate the percentage that the person scored on the quiz.
def gen(qna):
print(qna)
msg = input()
return msg
corrqs = 0 #used to determine score
#pre quiz questions: name, "are you ready?"
print("what is your name?")
name = input()
print(name + ", are you ready to take a quiz?")
ans = input()
if ans == "yes":
print("ok, good luck!")
else:
print("ok, bye!")
quit()
#lists including questions and answers
questions = ["What command is used to include other functions that were previously developed?", "What command is used to evaluate correct or incorrect response in this example?", "Each 'if' command contains an '_________' to determine a true or false condition?"]
answers = ["import", "if", "expression"]
#for loop, looping the questions function with questions and answers from lists
for i, question in enumerate(questions):
answer = answers[i]
resp = gen(question)
if resp == (answer):
print("your answer, " + str(resp) + ", is correct!")
corrqs += 1
else:
print("your answer, " + str(resp) + ", is incorrect!")
numqs = len(questions) #also used to determine score
score = (corrqs/numqs) #correct questions/total questions ratio(decimal)
per = (score * 100) # multiply by 100 for percentage
print("good job " + name + ", you scored " + str(per) + " percent on this quiz!") #final message with score