Im having some problems with the code below. I'm using PyCharm. The program is supposed to get an input for password of the user and check if it has at least 3 upper case chars and at least 3 numbers. The second task is what im having troubles with.
import sys
def num(s):
regex = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
for k in regex:
if regex == s:
print(y)
y = y + 1
return y
passw = input("Enter password")
passw2 = list(passw)
lenght = (len(passw2))
if lenght < 8:
print("Password needs to be at least 8 chars long")
else:
i = 0
for x in passw2:
if x.isupper():
i += 1
if i < 3:
print("You need at least 3 upper cased chars in your password")
sys.exit()
else:
numpassw2 = num(passw2)
if numpassw2<3:
print("At least 3 numbers needs to be given")
else:
print("OK,lets continue")
It gets stuck at calling out the num() function and gives following errors:
Traceback (most recent call last):
File "H:/szkola/python/projects/password/passwchecker.py", line 27, in <module>
numpassw2 = num(passw2)
File "H:/szkola/python/projects/password/passwchecker.py", line 10, in num
return y
UnboundLocalError: local variable 'y' referenced before assignment