0
def signUp():
    id=input("enter your id")
    password=input("enter your password")
    if (len(id) == 9 & len(password) > 4):
        print("YOUR ACCOUNT IS CREATED.....")
    else:
        print("Invalid ID or password")

Although I'm giving ID of length 9 and password of length greater than 4, still the condition isn't working. It's going to else always. But if I'm using nested if for ID and password, it's working fine.

Could you please help.

  • 1
    Use the `and` keyword, not the `&` operator here. `&` is a bitwise "and" operation which works on integers, and has a higher precedence than `==`, so this code is definitely not doing what you intended. – kaya3 Jan 21 '20 at 01:56
  • Does this answer your question? [Are & and equivalent in python?](https://stackoverflow.com/questions/32941097/are-and-and-equivalent-in-python) – mkrieger1 Jan 21 '20 at 02:10

1 Answers1

1

& is bit-wise AND. You want logical and:

if len(id) == 9 and len(password) > 4:
Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251