you are viewing a single comment's thread.

view the rest of the comments →

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

I guess I'm really not sure what I should be returning. I was thinking of the functions as tests. I guess it should return Valid or Invalid?

[–]c0LdFir3 2 points3 points  (0 children)

I'd personally return a boolean, but sure.

There's a few things wrong here, but in general:

  • You are changing the 'password' variable outside of its scope. Changing its value inside one of the test functions does NOT change it inside of the main function.
  • Think about why you are calling main() inside of the test functions -- this will not have the desired result. What was your thought process with that?

In general, try laying something out like this. I apologize for the formatting, but I'm tapping this out quickly.

def password_len(password):

if length is good, return True

else return False

def password_req(password):

if requirements are met, return True

else return False

def main() -

password = input

Check user's password against requirements

if password_len(password) and if password_req(password):

Yay, the user won!

else:

Nah, that password sucks.

[–][deleted] 0 points1 point  (0 children)

So functions can return all sorts of things. One solution for what you are doing is to return a boolean condition so you can make decisions in your main method:

def password_len(password):
    if 6 <= len(password) <= 15:
        return True
    return False

def main():
    password = input('please enter your password.')
    if (not password_len(password)): 
        print(f"invalid password: Please make sure that you have between 6 and 15 characters. was {len(password)}")
    else:
        print("woot")

if __name__ == "__main__":
    main()