Ad

Why Doesn't Input Return A The Print Value With .lower() Or .upper() Commands?

- 1 answer

When i run the code my python doesn't recognize what i put in whether it's with .lower or .upper, why is that?

import sys

Good = input('Am i Good? > ').upper()
if Good == 'no':
print(True, 'You are good')
elif Good == 'no':
print(True, ' You are still good')
elif Good == 'quit':
sys.exit()
Ad

Answer

In this line of code:

Good = input('Am i Good? > ').upper()

You transform the input to uppercase, but then you compare the string with lowercase strings ("no", "quit"). This will never match since "NO" and "no" are different strings (Python cares about case when comparing strings).

Ad
source: stackoverflow.com
Ad