-2

I want my Python code to accept both uppercase and lowercase input.

I've tried casefold, but with no luck. Any help?

advice =""
while advice !=("Yes"):
      print("Would you like some advice!")
      advice = input("Yes or No?    ")
print("Always listen to your IT Teacher!")

I would like the input to accept Yes and yes as user input.

unbindall
  • 514
  • 1
  • 13
  • 29
  • 2
    Did you mean something like: `while advice.upper() !=("YES"):` – Nir Alfasi Feb 09 '15 at 09:37
  • Welcome to SO! Here, we solve non-working code in a Q&A format. Please do some elementary research before posting a question. For more info on site policies, refer to the FAQ. – bluefog Feb 09 '15 at 09:42
  • Note that none of the answers here would pass the [Turkey Test](http://www.moserware.com/2008/02/does-your-code-pass-turkey-test.html) – Daniel Pryden May 01 '15 at 00:00
  • Possible duplicate of [How to let Python recognize both lower and uppercase input?](https://stackoverflow.com/questions/12719586/how-to-let-python-recognize-both-lower-and-uppercase-input) – palvarez Aug 20 '19 at 14:42

1 Answers1

4

You could just make advice uppercase eg.:

while advice.upper() != "YES"

This way it doesn't matter if the user inputs lower or upper case (or a mix).

glglgl
  • 89,107
  • 13
  • 149
  • 217
I_Khanage
  • 456
  • 1
  • 6
  • 8
  • 3
    I would do the same with `.lower()` and `"yes"`, but that is probably a matter of personal choice. – glglgl Feb 09 '15 at 09:40
  • True you could use lower() doesn't matter really. Personally if I'm using a string constant I like to make it all uppercase to show that it is a constant but that's just me. – I_Khanage Feb 09 '15 at 09:43
  • Thank you, sometime its the simplest things you cannot see, feel silly now!! – Diane Collins Feb 09 '15 at 09:43