-1

用户必须输入密码,但密码中必须至少有1个大写、小写和数字。

password = input("Please enter a password: ")
4

2 回答 2

4
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.")
于 2013-09-26T21:28:13.207 回答
1

您还可以放入一个在匹配这些条件之前不会停止的 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!')
于 2013-09-26T21:30:12.500 回答