-1

my Code doesent understand letters in the list i would like somone to help me fix this

usernames = (BTP, btp, Btp, BTp)
def username(usernames2):
    if usernames == input('whats your username? : ')

Its a simple username system, i plan to use for a interface im making.

Dalija Prasnikar
  • 27,212
  • 44
  • 82
  • 159
  • 1
    *usernames* is not a list - it's a tuple. Presumably BTP, btp, Btp & BTp are declared elsewhere in your code. Input returns a string and therefore will never be equal to a tuple. I recommend https://www.python.org/about/gettingstarted/ – DarkKnight Nov 17 '22 at 17:27
  • I dont even know where to start – mnikley Nov 17 '22 at 17:28
  • This question is hard to understand. You need to think more about what you're asking and include that in your question along with what you get when you run this code and what you expect. Several problems in your code - the username function takes a usernames2 argument but the function uses usernames, you are comparing the usernames tuple to the result of input rather than checking if input is in tuple, etc. – inteoryx Nov 17 '22 at 17:28
  • No it is not also this is the Full code – BryanThePotato Nov 17 '22 at 17:28
  • 2
    Do you mean that python doesn't understand that when you type `BTP` you really meant to type `'BTP'`? In any event, letters are strings, and Python understands them perfectly well. You just need to use the right syntax when working with them. – John Coleman Nov 17 '22 at 17:29
  • I'm asking how do i make my list At the beginning of the code understand words as of my knowledge it can only understand numbers – BryanThePotato Nov 17 '22 at 17:29
  • 1
    The question is not clear. Do you mean usernames = ('BTP', 'btp', 'Btp', 'BTp') – chexxmex Nov 17 '22 at 17:29
  • I am sorry I'm stupid and forgot to add the '' – BryanThePotato Nov 17 '22 at 17:34
  • it wont let me delete :( – BryanThePotato Nov 18 '22 at 18:19

2 Answers2

1

usernames is defined as a tuple of 4 items, with the names BTP, btp, Btp, and BTp. You said "list" in your title but your code has no actual lists. Lists use brackets, tuples use parentheses.

Anyway, I'm assuming you actually want to check if the user's input actually was equal to the letters "btp" and you want the check to be case-insensitive, hence why you included all combos of uppercase and lowercase.

The main issue is that you didn't put quotes around the strings, so you have just 4 bare names sitting in your code which the interpreter expects to have been defined previously. But, you actually don't have to define all the possible combinations of uppercase and lowercase in the first place - there's a much easier method to do a case-insensitive string compare, here.

So, your code just needs to look like:

usename = "btp"
def username(usernames2):
    if input('whats your username? : ').lower() == username

Or, if you want to check against multiple usernames, you can use the in operator:

usenames = ["btp", "abc", "foo", "bar"]
def username(usernames2):
    if input('whats your username? : ').lower() in usernames
Random Davis
  • 6,662
  • 4
  • 14
  • 24
0

If you haven't declared BTP, btp, Btp, and BTp you will get a NameError

If you wanted to use strings you need single or double quotation marks:

usernames = ("BTP", "btp", "Btp", "BTp")

With that you create a tuple containing four string elements.

The next issue is with your if condition as you compare if a tuple is equal a string.

Try storing the input given from the user in a variable:

def username(usernames):
    user_input = input('whats your username?: ')
    if user_input in usernames:
        # Do something when username is found
Wolric
  • 701
  • 1
  • 2
  • 18