Why does this elif_statement not work? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Why does this elif_statement not work? (/thread-13251.html) |
Why does this elif_statement not work? - Placebo - Oct-06-2018 Hi! My code: feeling = input('How are you?\n') if feeling.lower() == 'great': print('I feel great too.') elif feeling.lower == 'bad': print('I hope the rest of your day will be good.') else: print('Take it easy!') and the output (please focus on the second execution) My question is apparently, why does my program print 'take it easy', instead of 'I hope the rest of your day will be good.', when the input is 'bad'?Can anyone please spot my error? RE: Why does this elif_statement not work? - ichabod801 - Oct-06-2018 You need parentheses after the lower on line 4. You're comparing the input to the method, not the result of calling the method. RE: Why does this elif_statement not work? - j.crater - Oct-06-2018 In line 4 you are not calling the lower method of a string. Instead you are comparing the string "bad" to the lower method. Instead you should use parentheses ( feeling.lower() ), like you did in line 2. RE: Why does this elif_statement not work? - Placebo - Oct-07-2018 Omg, lol, I have looked yesterday more than 10 times over the code, but just have overlooked it completely. Thanks for quickly clearing it up^^ |