鱼C论坛

 找回密码
 立即注册
查看: 2286|回复: 1

Python 0基础 课后作业第14题 怎么循环?

[复制链接]
发表于 2020-4-8 19:29:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 heidern0612 于 2020-4-9 07:44 编辑

依靠帖内大神的答案,搞懂了这题怎么写。
但是!突然想到,一半网站如果设计的密码等级过低,是不会通过的,所以正常应该还有个循环结构。


#-*- coding:gbk -*-
numbers = '0123456789'
words = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
symbols = r'''`!@#$%^&*()_+-=/*{}[]\|'";:/?,.<>'''
flag = 0
text = ('''请按以下方式提升你的密码安全级别:
\t1.密码必须由数字、字母及特殊字符三种组合
\t2.密码只能由字母开头
\t3.密码长度不能低于16位''')
password = input('请输入需要检查的密码组合:') . strip()

length = len(password)
if length:
    if length < 8:
        count_len = 1
    elif length >= 8 and length < 16:
        count_len = 2
    elif length >= 16:
        count_len = 3
   
    for each in password:
        if each in numbers:
            flag += 1
            break
    for each in password:
        if each in words:
            flag += 1
            break
    for each in password:
        if each in symbols:
            flag += 1
            break
    if count_len > 2 and flag > 2 and password[0] . isalpha():
        print('你的密码安全级别为:高,请继续保持。')
    elif count_len < 2 or flag < 2 or not password[0] . isalpha():
        print('你的密码安全级别为:低\n' + text)
    else:
        print('你的密码安全级别为:中\n' + text)

上面是那个帖子里大神的答案,@jackz007
现在想知道怎么加循环,如果加判断,又怎么加???
希望有大佬帮助小弟QAQ
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-4-8 19:42:38 | 显示全部楼层
我解救了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-28 12:21

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表