|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- '''
- 请用已学过的知识编写程序,找出小甲鱼藏在下边这个长字符串中的密码,密码的埋藏点符合以下规律:Y5d|MAp
- Y5d|MAp
- a) 每位密码为单个小写字母
- b) 每位密码的左右两边均有且只有三个大写字母
- '''
- password = ""
- with open("string2.txt","r",encoding="utf-8") as f:
- content = f.read()
- length = len(content)
- for i in range(length):
- if content[i] == "\n":
- continue
- if content[i].islower() and content[i+1:i+4].isupper() and len(content[i+1:i+4]) == 3 \
- and content[i-3:i].isupper() and len(content[i-3:i]) == 3:
- if content[i+4].islower() and content[i-4].islower():
-
- password +=content[i]
- print(password)
复制代码 content 如下
和答案差了一点,不知道是哪里没考虑全
因为content中有换行,得先把换行去掉:
- '''
- 请用已学过的知识编写程序,找出小甲鱼藏在下边这个长字符串中的密码,密码的埋藏点符合以下规律:Y5d|MAp
- Y5d|MAp
- a) 每位密码为单个小写字母
- b) 每位密码的左右两边均有且只有三个大写字母
- '''
- password = ""
- with open("string2.txt","r",encoding="utf-8") as f:
- content = f.read().replace('\n', '') # 注意这里
- length = len(content)
- for i in range(length):
- if content[i] == "\n":
- continue
- if content[i].islower() and content[i+1:i+4].isupper() and len(content[i+1:i+4]) == 3 \
- and content[i-3:i].isupper() and len(content[i-3:i]) == 3:
- if content[i+4].islower() and content[i-4].islower():
-
- password +=content[i]
- print(password)
复制代码
|
|