Can anyone give me some tips on how to make this shorter or maybe to take an arg

def pass_check():
    count = 0
    tri = 4
    while count < 5:
        count+=1
        asn = input("Enter a password: ")
        if len(asn) < 7:
            print("Password must be greater than 7.\nYOu have " + str(tri) + " left")
            tri-=1
        else:
            print("Access Granter.\n")
            break
            
pass_check()
1 Like

So a couple of things here.
First of all, you need to separate concerns. The pass_check function should not care about where the password is coming from(stdin etc.) It should only care about the input. Testing the current function will be tricky to replace the input with mock objects. You can restructure the code to this

def pass_check(password):
    #perform your validations
    pass

#application code to provide input for your function
password = input ("please enter your password")
pass_check(password)

Secondly make sure you function names are decriptive enough to give a developer an idea of what it does. You can name it as password_check or validate_password.

There more things you can do to expand on this.

2 Likes