鱼C论坛

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

零基础20讲 动动手1题问题

[复制链接]
发表于 2017-9-8 12:36:08 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 工程狗 于 2017-9-8 14:46 编辑

str1 = '''输入的字符串'''
alf = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
code = []
for each in str1:
    if each in 'abcdefghijklmnopqrstuvwxyz':
        position = str1.index(each)
        if position>2 and position+3<len(str1) and (str1[position-1] in alf) and (str1[position-2] in alf) and (str1[position-3] in alf) and (str1[position+1] in alf) and (str1[position+2] in alf) and (str1[position+3] in alf):
            code.append(each)
print(code)
我写的代码是这个,我知道我的逻辑错了,但是不知道为什么运行出来是很多字符串‘1‘的列表
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-9-8 23:54:34 | 显示全部楼层
题目没有描述清楚哈
但大概知道你的意思
是不是很多重复的字母,如果不想有重复字母在code里,我们可以再加判断:
if each not in code:
    code.append(each)

来群吧,扒皮风群欢迎你
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-7-1 20:23

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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