import getpass, sys, os
# Questions and answers
questions = [
"Which command allows people to import commands and funcitons?",
"What command defines a funciton?",
"Which command prints a specified messge on the screen?",
"Which command helps differentiate right from wrong?",
"Which command returns input from the user?",
"A collection of characters is called ____?"
]
correct_answers = [
"import",
"def",
"print",
"if",
"return",
"string"
]
#Quiz function
def run_quiz():
correct = 0
#keeps count of how many are correct
for i in range(len(questions)):
print(i)
#tells us which iteration it is on
rsp = question_with_response(i)
if rsp == correct_answers[i]:
print("Correct!")
correct +=1
else:
print(f"Incorrect, the correct answer is: {correct_answers[i]}")
# if it is correct, a point is added to correct. If not, the user is told it is incorrect, and the incorrect answer is shown
score = (correct/6)
#makes it easier to formate the number as a percentage
print("\nQuiz completed!")
print(getpass.getuser() + " you scored " + "{:.2%}".format(score))
# Prints the user's name, then you scored, and the score as a percentag, up to two decimal points
run_quiz()
0
Question 1: Which command allows people to import commands and funcitons?
Incorrect, the correct answer is: import
1
Question 2: What command defines a funciton?
Incorrect, the correct answer is: def
2
Question 3: Which command prints a specified messge on the screen?
Incorrect, the correct answer is: print
3
Question 4: Which command helps differentiate right from wrong?
Incorrect, the correct answer is: if
4
Question 5: Which command returns input from the user?
Incorrect, the correct answer is: return
5
Question 6: A collection of characters is called ____?
Incorrect, the correct answer is: string
Quiz completed!
cliang you scored 0.00%