isupper() 和 isdigit() 不能一起工作
isupper() and isdigit() not working together
我正在尝试创建一个简单的 passwprd 应用程序,我想检查我的密码是否满足某些要求。我希望它在某处既有大写字母又有数字。我使用 for 循环将密码的每个字母存储在列表中,然后检查列表中的每个元素是否为大写。但是当我在检查字母是否为大写的 if 语句中添加一个新的 if 语句来检查其中一个字符是否为数字时,if 语句没有 return 任何东西。
def check_password():
characters = []
if len(password_entry.get()) >= 8:
for i in range (len(password_entry.get())):
characters.append(password_entry.get()[i])
if characters[i].isupper():
if characters[i].isdigit():
register_user()
print("password valid")
else:
password_not_valid_upper()
else:
password_not_valid_length()
您要检查字符是否为大写,如果是,则检查它是否为数字。不可能两者兼而有之,所以你总是会落入其他 password_not_valid_upper().
我正在尝试创建一个简单的 passwprd 应用程序,我想检查我的密码是否满足某些要求。我希望它在某处既有大写字母又有数字。我使用 for 循环将密码的每个字母存储在列表中,然后检查列表中的每个元素是否为大写。但是当我在检查字母是否为大写的 if 语句中添加一个新的 if 语句来检查其中一个字符是否为数字时,if 语句没有 return 任何东西。
def check_password():
characters = []
if len(password_entry.get()) >= 8:
for i in range (len(password_entry.get())):
characters.append(password_entry.get()[i])
if characters[i].isupper():
if characters[i].isdigit():
register_user()
print("password valid")
else:
password_not_valid_upper()
else:
password_not_valid_length()
您要检查字符是否为大写,如果是,则检查它是否为数字。不可能两者兼而有之,所以你总是会落入其他 password_not_valid_upper().