用户必须输入密码,但密码中必须至少有1个大写、小写和数字。
password = input("Please enter a password: ")
用户必须输入密码,但密码中必须至少有1个大写、小写和数字。
password = input("Please enter a password: ")
if any(x.isupper() for x in password) and \
any(x.islower() for x in password) and \
any(x.isdigit() for x in password):
print ("Congratulations, you have a secure password.")
您还可以放入一个在匹配这些条件之前不会停止的 while 循环:
while True:
password = input("Please enter a password: ")
if any(x.isupper() for x in password) and \
any(x.islower() for x in password) and \
any(x.isdigit() for x in password): #copy from Rob's awnser
break
else: print('Invalid!')