如何确保输入符合要求

问题描述:

用户必须输入密码,但密码中必须至少有1个大写,小写和数字。如何确保输入符合要求

password = input("Please enter a password: ") 
+3

设法解决它的一个组成部分。其余的将会很容易。如果您遇到困难,请告诉我们您尝试了什么。 –

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!')