How to generalize upper and lower case input in Python
Go to solution
Solved by HunterAP,
Like Nocte said, you can use the upper() and lower() functions.
Basically you take the user input, make it lowercase using the lower() function, then compare it to your options in lowercase, like so:
# Creating decision maker import random a = input("Magic 8 Ball, Do you want any advice?\n") if a.lower() == "yes": b.lower() = input("Type 'shake' to activate Magic 8 Ball\n") if b == "shake": c = input("Ask me anything and you shall get the answer, press enter after you have it in your mind\n") print(random.choice(["Surely", "Most Probably", "Nop", "Louder man", "You might wanna think about that", "Maybe", "Probably", "Maybe not"])) else: exit() elif a == "no": print("Okay, goodbye; See ya Later") elif a == "": print("Type something man")
I also added proper indentation. You also don't need the
if c == "":
statement because the code is supposed to give a response regardless of the question.
Lastly, you didn't need the
elif b == "":
code snippet and instead can make it into a simple "else" statement.

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now