My Python Quiz
Quiz I made for you:
import getpass, sys #
def question_with_response(prompt):
print("Question: " + prompt)
msg = input()
return msg
questions = 3
correct = 0
print('Hello, ' + getpass.getuser() + " running " + sys.executable)
print("I will quiz you on these " + str(questions) + " questions.")
def question_and_answer(prompt): #question and answer command
print("Question: " + prompt)
msg = input()
print("Answer: " + msg)
question_and_answer("Are you ready to take my quiz?")
rsp = question_with_response("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("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("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!")
#key vocabulary:
rsp = question_with_response("'Hello, World' is a String literal. This is the referred to as _____, as it does not change?")
if rsp == "static text":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
rsp = question_with_response("Two or more lines of code forms a:")
if rsp == "sequence of code":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
rsp = question_with_response("Grouping a sequence of commands, often used repeatedly, is called:")
if rsp == "procedural abstraction":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
rsp = question_with_response("What key word in Python defines a function?")
if rsp == "def":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
print(getpass.getuser() + " you scored " + str(correct) +"/7")