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("You will be asked " + str(questions) + " questions.")
question_with_response("Are you ready to take a test?") # Corrected function call
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!")
print(getpass.getuser() + " you scored " + str(correct) +"/" + str(questions))
Hello, ellier running /bin/python
You will be asked 3 questions.
Question: Are you ready to take a test?
Question: What command is used to include other functions that were previously developed?
is incorrect!
Question: What command is used to evaluate correct or incorrect response in this example?
is incorrect!
Question: Each 'if' command contains an _________ to determine a true or false condition?
is incorrect!
ellier you scored 0/3
My Updated Quiz
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("You will be asked " + str(questions) + " questions.")
question_with_response("Are you ready to take a test?")
quiz = [
("If expressions are evaluated to ___ ___?", "true false"),
("What key word defines a function?", "def"),
("What do functions take?", "parameters")
]
for question, answer in quiz:
rsp = question_with_response(question)
if rsp == answer:
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
print(getpass.getuser() + " you scored " + str(correct) + "/" + str(questions))
Hello, ellier running /bin/python
You will be asked 3 questions.
Question: Are you ready to take a test?
Question: If expressions are evaluated to ___ ___?
true false is correct!
Question: What key word defines a function?
def is correct!
Question: What do functions take?
parameters is correct!
ellier you scored 3/3