<!DOCTYPE html>
Mort Quiz With Response
In [ ]:
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? import is correct! Question: What command is used to evaluate correct or incorrect response in this example? if is correct! Question: Each 'if' command contains an '_________' to determine a true or false condition? expression is correct! ellier you scored 3/3
My Updated Quiz
In [ ]:
import getpass
import sys
print('Hello, ' + getpass.getuser() + " running " + sys.executable)
print(f"You will be asked {len(questions)} questions.")
input("Are you ready to take a test? Press Enter to continue...")
def ask_question(question, expected_answer):
print("Question:", question)
answer = input()
return answer == expected_answer
questions = [
("If expressions are evaluated to ___ ___?", "true false"),
("What key word defines a function?", "def"),
("What do functions take?", "parameters")
]
correct = sum(ask_question(q, a) for q, a in questions)
print(getpass.getuser() + f", you scored {correct}/{len(questions)}")
Hello, ellier running /bin/python You will be asked 3 questions. Question: If expressions are evaluated to ___ ___? Question: What key word defines a function? Question: What do functions take? ellier, you scored 2/3