Reputation: 33
I'm struggling with my password rater program. How can i make sure that when i insert a password, my program returns the password strength. When i run this program it says that password_strength is stored at .....) is the return that i call at the end of my program wrong?
print ("Welcome to this password rater program")
print ("Your password needs to have a minimum of 6 characters with a maximum of 20 characters.")
print ("Your password can contain lowercase and uppercase characters, numbers and special characters")
print("")
password = input("Please insert your password: ")
def check_len(password):
l = len(password)
if 6 < l < 20:
x = check_char(password, l)
else:
x = 0
return x
def check_char(password, l):
for i in range(l):
ascii = ord(password[i])
num = 0
upper = 0
symbols = 0
lower = 0
space = 0
if 96 < ascii < 123:
lower = 15
elif 47 < ascii < 58:
num = 25
elif 64 < ascii < 91:
upper = 25
elif ascii == 32:
space = 30
else:
symbols = 25
total = ((lower + num + upper + space + symbols) * len(password))
return total
def password_strength(total):
if total >= 1000:
print("Your chosen password is Very strong")
elif 700 < total < 999:
print("Your chosen password is strong")
elif 500 < total < 699:
print("your chosen password is medium")
elif total <= 500:
print("Your chosen password is weak")
return total
strength = check_len(password)
print(password_strength(strength))
Upvotes: 1
Views: 128
Reputation: 626
Well first of all, you tell python to print the function, not the evaluation of the function. This is why you get that message.
Also, you never call any of the functions you wrote. To get a working program after the declaration of all definitions is the following:
Call the check_len definition:
strength = check_len(password)
This definition doesn't return any value though. You could change it to:
def check_len(password):
l = len(password)
if 6 < l < 16:
x = check_char(password, l)
else:
x = 0
return x
To have it return the score/strength.
Finally you should process the score using your 'password_strength' definition:
password_strength(strength)
In this line there is no need to print, because the printing statements are in the definition itself. If you want to print the final score as well though, you could make it into the following line:
print(password_strength(strength))
One more debug thingy: your check_char definition doesn't take any arguments. You could solve this by changing it into:
def check_char(password, l):
Final code: print ("Welcome to this password rater program") print ("Your password needs to have a minimum of 6 characters with a maximum of 16 characters.") print ("Your password can contain lowercase and uppercase characters, numbers and special characters") print ("")
password = raw_input("Please insert your password: ")
def check_len(password):
l = len(password)
if 6 < l < 16:
x = check_char(password, l)
else:
x = 0
return x
def check_char(password, l):
for i in range(l):
ascii = ord(password[i])
num = 0
upper = 0
symbols = 0
lower = 0
space = 0
if 96 < ascii < 123:
lower = 15
elif 47 < ascii < 58:
num = 25
elif 64 < ascii < 91:
upper = 25
elif ascii == 32:
space = 30
else:
symbols = 25
total = ((lower + num + upper + space + symbols) * len(password))
return total
def password_strength(total):
if total >= 1000:
print("Your chosen password is Very strong")
elif 700 < total < 999:
print("Your chosen password is strong")
elif 500 < total < 699:
print("your chosen password is medium")
elif total <= 500:
print("Your chosen password is weak")
return total
strength = check_len(password)
print(password_strength(strength)) `
Upvotes: 3
Reputation: 5469
You never call your python functions.
def potatis():
print("Hello yu!")
defines a function, but you also need to call the function potatis()
for the code inside to actually run.
Upvotes: 1