0

so I tried to list some variables and I keep getting a syntax error.

usr1 = 'boy'
usr2 = 'girl'
usr = input("What's your username: ")
if usr != usr1, usr2:
   print('Username not found, try again')

then I get an error

if usr != usr1, usr2:
              ^
SyntaxError: invalid syntax

I also tried to remove the commas, same error, thanks

1
  • 2
    if usr not in (usr1, usr2) Commented Sep 4, 2020 at 4:46

3 Answers 3

1

You can't compare with two variables like that. You need to do two separate comparisons and combine them with a logical operation.

if usr != usr1 and usr != usr2:

Or you can put all your usernames in a collection:

valid_users = {usr1, usr2}
if usr not in valid_users:
Sign up to request clarification or add additional context in comments.

Comments

0

This snippet might solve your question

usr1 = 'boy'
usr2 = 'girl'
usr = input("What's your username: ")
if usr != usr1 and usr != usr2:
    print('Username not found, try again')

Comments

0
usr1 = 'boy'
usr2 = 'girl'
usr = input("What's your username: ")
if usr not in [usr1, usr2]:
   print('Username not found, try again')

Or you can use

usr1 = 'boy'
usr2 = 'girl'
usr = input("What's your username: ")
if usr!=usr1 and usr!=usr2:
   print('Username not found, try again')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.