+ 1
Why doesn't this work?
I have just made a custom quiz function to make quizzes more easily, and if I input the correct answer as the input in the code, it outputs "correct", but when I put in an input function as the input, and input the correct answer, it outputs "try again". Any ideas why? I made sure I was spelling it right as well. https://sololearn.com/compiler-playground/c5t8TcFKH3qA/?ref=app
4 Réponses
+ 4
it's answer.lower() instead of answer.lower and so one. you can also simplify your code a little by removing the str() – input() always gives a string.
https://sololearn.com/compiler-playground/cV60vAxiENrr/?ref=app
+ 2
input() always gives a string, no matter what
0
Lisa thanks, that helps, but I want to keep the str part in there just in case the input is, for some reason, not a string. but the .lower() part helps. edit: I guess for the "(Answer) is not None" part, I need to get rid of the str
0
def quiz(answer, input, question=None, correct="Correct!", incorect="Try again."):
if (question):
print(question)
if answer.lower()==input.lower():
return correct
return incorect
print(quiz('why',str(input()),"who what when where which how _?_"))