First Python Quiz
A quiz by Luke Angelini
print ("Write the letter for the correct answer below.")
class Question:
def __init__(self, prompt, answer):
self.prompt = prompt
self.answer = answer
question_prompts = [
"What function is used to output text? \n(a)print \n(b)write \n(c)say",
"What keyword is used to define a function? \n(a)define \n(b)function \n(c)def",
"What command allows the use of previously developed functions? \n(a)recall \n(b)import \n(c)function",
"What function is used to collect user input? \n(a)input \n(b)import \n(c)collect",
]
questions = [
Question(question_prompts[0], "a"),
Question(question_prompts[1], "c"),
Question(question_prompts[2], "b"),
Question(question_prompts[3], "a"),
]
def run_quiz(questions):
score = 0
for question in questions:
answer = input(question.prompt)
if answer == question.answer:
score += 1
print("You got" + str(score) + "/" + str(len(questions)) + "correct.")
run_quiz(questions)
new_quiz = []
new_quiz.append({
"What function is used to output text?":"print",
"What keyword is used to define a function?":"def",
"What command allows the use of previously developed functions?":"import",
"What function is used to collect user input?":"input"
})