如果我首先输入有效的数据,它可以正常工作,但如果我输入无效数据,然后是有效数据,则返回 None。这是问题的一个例子:
代码:
def passwordLength(password):
if (len(password) < 4) or (len(password) > 15):
print("Error from server: Your password must be at least four and at most fifteen characters long.")
enterPasswords()
else:
return True
def passwordMatch(password, password2):
if password != password2:
print("Error from server: Your passwords don't match.")
enterPasswords()
else:
return True
def enterPasswords():
password = input("Message from server: Please enter your desired password: ")
if passwordLength(password):
password2 = input("Message from server: Please re-enter your password: ")
print(password, password2)
if passwordMatch(password, password2):
print(password)
return password
password = enterPasswords()
print(password)