|
20鱼币
[课后作业] 第020讲:函数:内嵌函数和闭包 | 课后测试题及答案 [color=rgb(153, 153, 153) !important]
[color=rgb(153, 153, 153) !important]
[color=rgb(153, 153, 153) !important]动动手:
[color=rgb(153, 153, 153) !important]1. 请用已学过的知识编写程序,找出小甲鱼藏在下边这个长字符串中的密码,密码的埋藏点符合以下规律:
a) 每位密码为单个小写字母
b) 每位密码的左右两边均有且只有三个大写字母
(由于我们还没有学习到文件读取方法,大家下载后拷贝过去即可)
请下载字符串文件: string2.txt (8.21 KB, 下载次数: 252)
[color=rgb(153, 153, 153) !important]
谁可以给我讲一下这个程序的实现过程呢,实在看不懂,各位对我这种以前没怎么学习编程语言的学生有什么好的学习python的建议么,求大神指点!
答案代码如下:
- str1 = '''拷贝过来的字符串'''
- countA = 0
- countB = 0
- countC = 0
- length = len(str1)
- for i in range(length):
- if str1 == '\n':
- continue
- [i] if str1.isupper():[/i]
- if countB == 1:
- countC += 1
- countA = 0
- else:
- countA += 1
- continue
- [i][i] if str1.islower() and countA == 3:[/i][/i]
- countB = 1
- countA = 0
- target = i
- continue
- [i][i][i] if str1.islower() and countC == 3:[/i][/i][/i]
- print(str1[target], end='')
- countA = 0
- countB = 0
- countC = 0
|
|
最佳答案
查看完整内容
也是初学,给几个建议,不一定对:
建议一:发帖,复制粘贴可以,但也请稍微编辑下,一堆的、等等html标签看着太乱,也显得没诚意。
建议二:帖子中的代码最好用代码格式,就是发帖框中的标志,这样看的清楚。
建议三:代码应该是自己照答案敲的吧,有关键性的错误,不看@小甲鱼 的答案,谁都看不明白。
建议四:问题最好能具体些,哪句代码没明白,哪个变量不知道意义。
具体这个题目的实现:代码的思路就是题目中的问题,先 ...
|