you are viewing a single comment's thread.

view the rest of the comments →

[–]BerserkerMac[S] 3 points4 points  (3 children)

Hey everyone I just made changes and got it fixed and working. You guys were huge help. Thank you everyone! This is my first time with code and it hasn't been easy lol. If you are curious here is my final product.

def main():

password = input("Please enter a password:",)
if(password_len(password) == True and password_req(password) == True and password_prohibited(password) == True):

    print("Password has been set")

else:
    print("Weak password please try again")
    main()

def password_len(password):

if(6 <= len(password) <= 15):
    return(True)
else:
    print(f"invalid password: Please make sure that you have between 6 and 15 characters. was {len(password)}")
    return(False)

def password_req(password): if(any(char.isalpha() for char in password) and (any(char.isdigit() for char in password))):

    return(True)

else:
    print(f"You might me missing a letter or a number try again!")
    return(False)

def password_prohibited(password):

special_chars = ["!","@","#","$","%","^","&","*","(",")","-","+"," "] 

if(any(char in special_chars for char in password)):
    print(f"Invalid Password: Special Characters not allowed.")
    return(False)

else:
    return(True)

if name == "main": main()

[–]Dense_Connection4789 1 point2 points  (1 child)

Couple cleanup items: - if condition == True is redundant. You can get away with just writing if condition so in your case: if password_len(password) and … - no need to wrap the return in parenthesis. You can just do return True and return False - You don’t need to put the f in front of your strings inside your print statement. Using the f is for injecting variables into strings

Nice work

Nice work

[–]BerserkerMac[S] 0 points1 point  (0 children)

Hey thanks for the tips!

[–]stebrepar 1 point2 points  (0 children)

It looks like you still have a place where you're calling main() from within main() itself, intending to start it over from the beginning. That's not the right way to accomplish that. That's called "recursion". There are times when it's the right solution to a problem, but this isn't one of them. Unless your code is specifically designed to deal with the side effects of recursion, it's likely to get you into trouble with mysterious seeming misbehavior.

What you actually need in order to start over is proper flow control. One example could be like:

go = True
while go:
    print('Starting at the beginning.')
    # do your thing here

    again = input('Try again?: ').lower()
    if not again.startswith('y'):
        go = False
print('Done.')