题意概括:输入密码判断合法性
密码要求:不少于六位,只能含有英文 数字 小数点,并且需要同时包含数字和字母
解题思路:直接统计字母 数字 和非法字符或者小数点的数量 就行了
代码如下:
n = int(input())
flag = 0
while flag<n:
l = input()
shuzi = 0
zimu = 0
feifa = 0
for i in range(len(l)):
if l[i].isdigit() == True:
shuzi +=1
elif l[i].isalpha() == True:
zimu +=1
elif l[i] != '.':
feifa +=1
if len(l) <6:
print('Your password is tai duan le.')
elif feifa != 0:
print('Your password is tai luan le.')
elif shuzi == 0:
print('Your password needs shu zi.')
elif zimu == 0:
print('Your password needs zi mu.')
else:
print('Your password is wan mei.')
flag +=1
提交结果: