Python Quiz
Prints something
This is my quiz about python! First, I greet the user, and ask them if they are ready Whatever their response is, I respond appropriately and begin he quiz I generate two lists, one with 5 questions and the other with the corresponding answers to the questions I iterate through the list, asking the user for the answer to the input If the answer is correct, I add one to the score I then print the number they have correct so far At the end, i print their total number correct out of 5, and calculate the percentage
import getpass, sys
print("Hello, "+getpass.getuser()+". Prepare to fail(but not actually)") # greets user
print("You will be graded out of 5 questions and will have a final score out of 5 and a percentage") # explains quiz
if input("Ready?") == "yes":
print("Great, let's go!")
else:
print("Too bad, we're still doing it")
questions = ["What command is used to include other functions that were previously developed?",
"What command is used to evaluate correct or incorrect response in this example?",
"Each 'if' command contains an '_________' to determine a true or false condition?",
"How many equal signs do you need to use in a comparison?",
"What keyword defines a function?"] # list of questions
answers = ["import","if","expression","2","def"] # list of answers
#Keeping a list of questions and answers to compare
correct = 0
for i in range(1,6):# iterate through list of questions/answers
ans = input("Question "+str(i)+": "+questions[i-1])#Asking question to user
if ans == answers[i-1]:
print(ans+" is correct ")
correct+=1#Adding to score if answer is correct
else:
print(ans+" is wrong")
print(str(correct)+"/"+str(i))# printing num correct by num total
print("Final Score: "+str(correct)+"/"+"5 "+str(correct*100/5)+"%")#Multipyling by 100 to get percentages
print("Good Job!")