|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
[课后作业] 第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[i] == '\n':
- continue
- if str1[i].isupper():
- if countB == 1:
- countC += 1
- countA = 0
- else:
- countA += 1
- continue
- if str1[i].islower() and countA == 3:
- countB = 1
- countA = 0
- target = i
- continue
- if str1[i].islower() and countC == 3:
- print(str1[target], end='')
- countA = 0
- countB = 0
- countC = 0
|
|