Vocabulary/Key Learning Quiz
Hello to Python Hacks
import getpass, sys
def question_and_answer(prompt):
print("Question: " + prompt)
msg = input()
print("Answer: " + msg)
def question_with_response(prompt):
print("Question: " + prompt)
msg = input()
return msg
def evaluate_answer(answer, response, correct):
if response == answer:
print(response + " is correct!")
correct += 1
else:
print(response + " is incorrect!")
return correct
questions = 3
correct = 0
print('Hello, ' + getpass.getuser() + " running " + sys.executable)
print("You will be asked " + str(questions) + " questions.")
question_and_answer("Are you ready to take a test?")
rsp = question_with_response("Which key word in Python is used to define a function?")
correct = evaluate_answer("def", rsp, correct)
print(correct)
rsp = question_with_response("What is a synonym for a procedure?")
correct = evaluate_answer("function", rsp, correct)
print(correct)
rsp = question_with_response("What do two or more lines of code form?")
correct = evaluate_answer("sequence", rsp, correct)
print(correct)
print(getpass.getuser() + " you scored " + str(correct) +"/" + str(questions))