鱼C论坛

 找回密码
 立即注册
查看: 1658|回复: 3

[已解决]第014讲:字符串:代码这么写为什么会报错?

[复制链接]
发表于 2020-3-5 18:29:48 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 一个账号 于 2020-3-5 18:42 编辑
password = input("请输入需要检查的密码组合:")
str1 = '~' in password
str2 = '!' in password
str3 = '@' in password
str4 = '#' in password
str5 = ' in password
str6 = '%' in password
str7 = '^' in password
str8 = '&' in password
str9 = '*' in password
str10 = '(' in password
str11 = ')' in password
str12 = '_' in password
str13 = '=' in password
str14 = '-' in password
str15 = '/' in password
str16 = ',' in password
str17 = '.' in password
str18 = '?' in password
str19 = '<' in password
str20 = '>' in password
str21 = ';' in password
str22 = ':' in password
str23 = '[' in password
str24 = ']' in password
str25 = '{' in password
str26 = '}' in password
str27 = '|' in password
str28 = '\\' in password
str99 = str1+str2+str3+str4+str5+str6+str7+str8+str9+str10+str12+str13+str14\
        +str15+str16+str17+str18+str19+str20+str21+str22+str23+str24+str25+str26+str27+str28
print(str99)
if len(password) <= 8 and str99 == 0:
    print("您的密码安全级别评定为:低")
    elif len(password) > 8 and str99 == 2:
        print("您的密码安全级别评定为:中")
        elif len(password) > 16 and str99 == 3:
           print("您的密码安全级别评定为:高")
最佳答案
2020-3-5 18:38:59
缩进错了吧,if ,elif缩进应该相同
另外,下次发代码记得点输入框上面的<>来插入
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-3-5 18:33:20 | 显示全部楼层
本帖最后由 一个账号 于 2020-3-5 18:47 编辑

缩进问题,第六行少了双引号,而且判断不合理,把代码改成这样:
password = input("请输入需要检查的密码组合:")
str1 = '~' in password
str2 = '!' in password
str3 = '@' in password
str4 = '#' in password
str5 = "'" in password
str6 = '%' in password
str7 = '^' in password
str8 = '&' in password
str9 = '*' in password
str10 = '(' in password
str11 = ')' in password
str12 = '_' in password
str13 = '=' in password
str14 = '-' in password
str15 = '/' in password
str16 = ',' in password
str17 = '.' in password
str18 = '?' in password
str19 = '<' in password
str20 = '>' in password
str21 = ';' in password
str22 = ':' in password
str23 = '[' in password
str24 = ']' in password
str25 = '{' in password
str26 = '}' in password
str27 = '|' in password
str28 = '\\' in password
str99 = str1+str2+str3+str4+str5+str6+str7+str8+str9+str10+str12+str13+str14\
        +str15+str16+str17+str18+str19+str20+str21+str22+str23+str24+str25+str26+str27+str28

if len(password) <= 6 or str99 <= 3:
    print("您的密码安全级别评定为:低")
elif len(password) <= 12 or str99 <= 6:
    print("您的密码安全级别评定为:中")
else:
   print("您的密码安全级别评定为:高")
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2020-3-5 18:38:59 | 显示全部楼层    本楼为最佳答案   
缩进错了吧,if ,elif缩进应该相同
另外,下次发代码记得点输入框上面的<>来插入
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-3-5 18:39:55 | 显示全部楼层
一个账号 发表于 2020-3-5 18:33
缩进问题,把代码改成这样:

你这样不行的
输出的是0
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-11-23 21:08

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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