【发布时间】:2013-09-26 21:25:11
【问题描述】:
用户必须输入密码,但密码中必须至少有1个大写、小写和数字。
password = input("Please enter a password: ")
【问题讨论】:
-
尝试解决其中的一部分。那么剩下的就很容易了。如果您遇到困难,请向我们展示您的尝试。
标签: python if-statement input
用户必须输入密码,但密码中必须至少有1个大写、小写和数字。
password = input("Please enter a password: ")
【问题讨论】:
标签: python if-statement input
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!')
【讨论】: