Python Quiz
msg = "This took a lot of unnecessary sweat, blood, and tears to set up"
print(msg)
import getpass, sys
def question_with_response(prompt): #defines question_with_response
print("Question: " + prompt) #prints the question to the user
msg = input() #takes the user's input
return msg #returns the user's input as a printed answer
def question_and_answer(prompt):
print("Question: " + prompt)
msg = input()
print("Answer: " + msg)
questions = 8
correct = 0
print('Hello, ' + getpass.getuser() + " running " + sys.executable)
print("You will be asked " + str(questions) + " questions.") #str(questions) turns the number 8 that is = to questions into a string that can be printed
question_and_answer("Are you ready to take a test?")
rsp = question_with_response("What command is used to include other functions that were previously developed?") #asks the question in terminal
if rsp == "import": #verifies the answer by comparing user response to answer
print(rsp + " is correct!") #prints "is correct" if the rsp was 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!")
rsp = question_with_response("Two or more lines of code is known as a '_______'?")
if rsp == "sequence":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
rsp = question_with_response("What is it called when one groups a sequence of commands that are used repeatesdly?")
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 by defining a group of commands but not intitially running them?")
if rsp == "def":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
rsp = question_with_response("What statement must you use to place variables that are defined as numbers into strings?")
if rsp == "str()":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
rsp = question_with_response("What term is used to refer to the paramater which is a message output to the user to describe the input requested?")
if rsp == "prompt":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
print(getpass.getuser() + " you scored " + str(correct) +"/" + str(questions))