Python Quiz
8-29-2022
import getpass, sys
def question_with_response(prompt):
print("Question: " + prompt)
msg = input()
return msg
correct = 0
rsp = question_with_response("what is the keyword for defining a function?")
if rsp == "def":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
rsp = question_with_response("Which functions runs code if a specific requirement is met?")
if rsp == "if else":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
rsp = question_with_response("How would one print 'Hello world!'?")
if rsp == "print('Hello world!')":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
if correct == 3:
print("Good job you scored " + str(correct) +"/" + str(questions))
elif correct == 2:
print("You're getting there, you scored " + str(correct) +"/" + str(questions))
elif correct == 1:
print("Try studying more, you scored " + str(correct) +"/" + str(questions))
else:
print("You should study Python, you scored " + str(correct) +"/" + str(questions))