Apr-25-2024, 07:27 AM
If you want to compare a user-input of equality, but case-insensitive, then lower the user-input and compare it only with the lower variant of the string.
... user_input = input("Do your choice: ") if user_input == "b" or user_input == "B": print("User-Input was:", user_input) else: print("Got a different input")Same logic, but shorter:
... user_input = input("Do your choice: ") # first user_input.lower() is evaluated, then this is compared to "b" # the user_input itself is imutable, so user_input.lower() creates a new string with only # lower case characters if user_input.lower() == "b": # here the original user_input is used, which is not lowered print("User-Input was:", user_input) else: print("Got a different input")
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!