Basic Python Quiz
Includes different messages based on final percentage
import getpass, sys
def question_with_response(prompt):
print("Question: " + prompt)
msg = input()
return msg
questions = 6
correct = 0
firstQ = False
print('Hello, ' + getpass.getuser() + " running " + sys.executable)
print("You will be asked " + str(questions) + " questions.")
while firstQ == False:
rsp = question_with_response("Are you ready to take a test?")
rsp.lower()
if rsp == "yes":
print(getpass.getuser() +": yes")
print("Great!")
firstQ = True
elif rsp == "no":
print(getpass.getuser() +": no")
print("Too bad!")
firstQ = True
else:
print("It's a yes or no question.")
questionsList = [
["What command is used to include other functions that were previously developed?", "import"],
["What command is used to evaluate correct or incorrect response in this example?", "if"],
["Each 'if' command contains an '_________' to determine a true or false condition?", "expression"],
["What command is used to define functions?", "def"],
["What are two or more lines of code called?", "sequence"],
["What command is used to show text on your screen?", "print"]
]
for QAPair in questionsList:
question = QAPair[0]
answer = QAPair[1]
rsp = question_with_response(question)
rsp.lower()
if rsp == answer:
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
quotient=correct/questions
percentage=round((quotient * 100), 2)
print(getpass.getuser()+", you scored " + str(correct) +"/" + str(questions))
print("That's", percentage,"%!")
percentList = [
[100,"Perfect!"],
[90,"Great!"],
[80,"Nice!"],
[70,"Could be better"],
[60,"Needs improvement"],
]
for numbersPair in percentList:
numbers = numbersPair[0]
note = numbersPair[1]
if numbers + 10 > percentage >= numbers:
print(note)
if 60 > percentage > 0:
print("Skill issue?")
elif percentage ==0:
print("Very cool!!")
# I am so cool