+ 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

14th Jun 2024, 3:39 PM
Jonathan Dodge
Jonathan Dodge - avatar
4 ответов
+ 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
14th Jun 2024, 4:26 PM
Lisa
Lisa - avatar
+ 2
input() always gives a string, no matter what
14th Jun 2024, 8:52 PM
Joe
Joe - avatar
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
14th Jun 2024, 7:40 PM
Jonathan Dodge
Jonathan Dodge - avatar
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 _?_"))
15th Jun 2024, 12:13 AM
Bob_Li
Bob_Li - avatar