把两个while循环改为if,因为如果是while,当while里的条件成立时,当前while循环就是死循环,程序会一直卡在那里,然后根据代码逻辑,可以改为if条件判断语句;
然后再修改下检测复杂密码的逻辑应该就可以了。
修改如下:
symbols=r'''~!@#$%^&*()_=-/,.?<>;:[]{}|\^'''
numbers='0123456789'
alphabet='abcdefghijklmnopqrstuvexyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
temp=input('请输入密码:')
password=temp
length=len(password)
p1=0 # 密码长度为8个字符内的标志,默认0为假
p2=0 # 密码长度为大于8小于16个字符的标志,默认0为假
p3=0 # 密码长度为大于16个字符的标志,默认0为假
if 0<length<=8:
p1=1
elif 8<length<16:
p2=1
else:
p3=1
#print("p1=",p1)
#print("p2=",p2)
#print("p3=",p3)
cotn=0
cota=0
cots=0
if p1==1: # 如果密码长度是8个字符内
for each in password:
if each in numbers:
cotn += 1
for each in password:
if each in alphabet:
cota += 1
if cota >1 or cotn>1:
print('密码安全性为极低')
alpFind=0 # 密码是否存在字母的标志,默认0为没有
numFind=0 # 密码是否存在数字的标志,默认0为没有
symFind=0 # 密码是否存在特殊字符的标志,默认0为没有
if p3 == 1: # 如果密码大于等于16个字符
for each in password: # 遍历密码字符串
# 如果密码中存在字母,则字母标志置1,这个也可以去除,
# 因为下面检测了password第一个字符是否为字母,所以这个去除也可以
# 如果去除这个if判断,第四个if里也要同时去除 and alpFind==1 这个条件
if each in alphabet:
alpFind=1
if each in numbers: # 如果密码中存在数字,则数字标志置1
numFind=1
if each in symbols: # 如果密码中存在特殊字符,则特殊字符标志置1
symFind=1
# 如果密码第一个字符为字母,并且同时存在字母,数字,特殊字符,
# 则打印密码强度为'高级'
if password[0] in alphabet and alpFind==1 and numFind==1 and symFind==1:
print('高级')
break
# 中西兼备的厨师
class master():
sta = "厨师"
def cake(self):
print("制作手抓饼")
def cook(self):
print("制作传统煎饼果子")
class app(master):
def cook(self):
print("制作中西方口味融合的煎饼果子")
print("师傅")
shifu = master()
print(shifu.sta)
shifu.cake()
shifu.cook()
print("徒弟")
tudi = app()
print(tudi.sta)
tudi.cake()
tudi.cook()
————————————————————————————————————————————