I am somewhat new to coding. I am making a quiz where I read in questions from a csv file. I don't understand why my code will not print "Correct. Well Done." when the user inputs a correct answer. Instead, it always prints "Incorrect." I have made sure userInput
and answer is the same by printing them.
FILENAME = 'quiztest.csv'
def welcomeUser():
name = input("Hello. Please enter your name: ")
print("Welcome " + name + "!")
def readFile():
with open(FILENAME, "r") as file:
for line in file:
line = line.split(",")
question = line[0]
options = line[1]
answer = line[2]
askQuestion(question, options, answer)
def askQuestion(question, options, answer):
print(question)
print(options)
userInput = input("Please enter the answer: ")
print(userInput)
print(answer)
if userInput == answer:
print("Correct. Well Done.")
else:
print("Incorrect.")
readFile()
What is returned:
What is my name?
Tom Jeff Fred Sam
Please enter the answer: Sam
Sam
Sam
Incorrect.