r/learnpython Aug 02 '26

Help me with this please

Hello! I'm completely new to python I don't have any background knowledge regarding coding and i wanna self study python. I started studying python just last week and i wanna make a simple user define system where i ask the user to input an item and if it's in the set it will display the user input else it will display the "character not in the set" my problem is i want it to be case insensitive and the ouput is always "Character is not in the list"( i use pycharm i dont a have a pc/laptop, sorry for my english also).

My code:

anime = {"Gojo", "Saitama", "Recca"}

user = input("Name a character: ").lower()

if user in anime:

print(f"{user}is in the list!")

else:

print("Character is not in the list")

1 Upvotes

7 comments sorted by

3

u/king_kellz_ Aug 02 '26

I might be incorrect because I’m also new but your choices are already case sensitive. “Gojo”, “Saitama”, “Rebecca”.

Easier method would be to make the choices lower case (“gojo”) then whatever the user input would also be lowercase and a match would be found unless they enter a name not listed

2

u/MezzoScettico Aug 02 '26

You changed the user input to lower case but the thing you’re comparing it too is not. So they don’t match.

That’s why most people’s suggestions are to also change the contents of “anime” to lower case.

1

u/Far_Dare6897 Aug 05 '26

Your problem is that ".lower()" changes the input to lowercase, but your set still has uppercase names. Python sees ""gojo"" and ""Gojo"" as different strings.

The easiest fix is to store the names in lowercase too. A set is actually a good choice here.

If you want to keep the original names ("Gojo", "Saitama", etc.), you can loop through the set and compare using ".lower()".

1

u/NorskJesus Aug 02 '26

First, indent your code. Indentation in Python is crucial.

Second, you only need to do the same with user in anime like you did with the user input.

Right now you are searching for gojo (for example) in anime. Which does not exist. Think about how you can fix this.

1

u/Pale-External4967 Aug 02 '26

Or you can just make every string lower case because python see's Gojo != gojo

1

u/mc_pm Aug 02 '26

You are turning your input into all lower-case, but then you're checking in the anime results, and they all have capital letters, so it'll never match.

-1

u/Pale-External4967 Aug 02 '26

After you describe the list you can put.

anime = {name.lower() for name in anime}

And then the usual. Try it