《小甲鱼零基础学Python》020课后作业题:找隐藏…

2018-08-26 17:32:52来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

动动手:

1. 请用已学过的知识编写程序,找出小甲鱼藏在下边这个长字符串中的密码,密码的埋藏点符合以下规律:
    a) 每位密码为单个小写字母
    b) 每位密码的左右两边均有且只有三个大写字母

ACFlCTLIQlAIVMTqHFkswqbDDHtpgcWaXSSglUYKE
lqNsYCyaQXBzrFUbkAUAWAKrDgDtAlGMBqWQhpEwquZqWZJpslUfMllCwWptqINjrOBTLuPzwvXNbLCx
oFRritKRpJgBOaGPZdkUzvYnvYmAlEsVmKRXqyQUOdCBqLYyboOYeAQNLnkuiDXCiNiksSSRpDMVQQgs
TmYThnppfKSmkpjjceGLaMOvYgsvNkGENKgGtUSzVPlLMeephDKrWGNpAxBqRiCnQIuKwDZurIRsznUp
xhstMWpHdZzqeEnttlAHiWbhbIJpwKBAGsFWthBiwBDKTFzIUamELZJFLbmqOmwBIYBJIofAUyxTLUEm
LcOXzjIHFcfUfEWccbWzhVuIZMdTVsOaNsLTpHjrvFaYTnJUrqaYnUmbobfOXXtkjKjFUEhVNlPWeaIY
uABNuEDKFWiUaqQiBHGsgEmDSKiJKLkkzFWlobXIyUlDzGcwDnEOwwWxgFpebsslmKItazIYctPROSJp
ImDHusQIkoFQSmuqwdcPNERvflfHtkGTrtbQXqZUsazoxmbVTPIuuxKvfALAaGnIuIZwczCcoIRMncBs
timFGHPJPaHMPTLjsBjIwbbzKyghaDTUStzJceaYAneywwpvdiUJifPHtXmAwZPChWsDmwonzeeQCEiB
xWsJLAtrdVEOBxEaYiSabHdUwlXlDOAKzZUwozJoBGvnFttDkXdYdjQSzzhTIPfYpWVFdiFIqSbyPZIi
VoXunBPbAJVMWluPcIfHmjPeHaTyClCvTOucEYEZXbVDiZMsfeuruDGMmQEsHutzvzVmWvCoPRguBiHh
taTeaguPmNuAxzYJLEcdoApfIFBaLUqettjTJNlHZYlJZRRoKXEvFnoUHdPjDuXuT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zaSIdkJgeyMUnUmtXfnaIedbAInAuQssOQqBTLbvFRiqKqUSdUEmcRmN
LvAxlgliymfbjTwDSqNTLcAEIerzpUShNKkuehciEAYeGJOFFcOvurJFUyfZhQqzfaneiBcrPhaphSCB
StQiJvtoPhHcLUbriDUIfifVFnNtJfGlmcbQJSXsZfVjpbqnkMllUmHzLvEuSarSlNlNHsWvYlfhjMEA
epYTjoRGZeAAtURFeDfDxTYmOmONuQQBdcdncFGjhHmKlwqmUWoXuIXIxaaXnNThgPGtIlynrUIPLQTG
xXhattDrfBGbZRveKbgjzxJLdYREQlMeLtcIEUoyJocdAfUbymxuFLVjGkOQniiPParqoyQYfDYAQTkM
WLicLxpEFkBbwlKrTyYilKTtYkpVGxtOjYmcBDOrwFhFiGutmpTyTarUbVUeSevBTdaPDpjRkaEmLJMg
WsMhSGfIcBChcqrRKgKpjvGnFipjswgjetRtniMagakbCXAjpzWTtMlgZGCJwGyglpcLebrKWhgwJfWV
qGifWNEpCtjuejHoyVCdIxzMYGnfoslgTNAJdtVBWDVoGLzHSAVBTnhNIvAOExQNiJOIPPiHkdaRbfaP
ixDDoCDOOeAqvQJFxLWDICfGmufyxmaMshbvcrtjqqVtffZTnbtCOQfzRMGwOQEKaAmSWjnYdNgvdkmd
dQmaKZSdqKNrnvJlcyVMKuNWmuoOeyKecgjXbmSqnpjwJEaDYoehEklEgJyiksGxdEKgfYRXQecRZgfe
qKWGc

  第一次看题,觉得简单,于是写出以下代码:

  1. l = len(a)
  2. for i in range(3, l - 3):
  3.     if a[i].islower():
  4.         for j in range(1, 4):
  5.             if a[i + j].isupper() + a[i - j].isupper() == 2:
  6.                 if a[i + 4].isupper() + a[i - 4].isupper() == 0:
  7.                     print(a[i], end = '')

结果如下:

  1. asaazzllqqqpbbiidllmmbbismrrppqqrzpztijjcntjauuiiiooyaasookttqqfaauconeitwwhhoddduaayyvzmoumfaallldubbkkkljlqzqyyarrswvapxmcoqzftzwwhhggfrzzoootvvoyfasgnebxxllvvrrghwsvvvzojbooiwwffyhhptqqzqseeenzmmyxlwwthhodcvyyvjwdccbmtnfcifenpzhhqvwclfffoozzwwowccbstuqivqmtenwwfnqkkvkknaljlegeffccnmeebiisnuuflwkmazookbvtyjpeeddavxxttpprwwiiimmddzzgbooddbbguyiikljdzzvvharxgukyyojtqqcchdlsubnfniuuzzqhljiwdtccfyuunldaagscjsssxtnoysfkhoocxgfuymmcxooqiblufovmddgvjxalhwwdddemtccyyuhqqppddirfyeouuaamznaabnlfphhwzgxuzzaycfewyvqqppvuuwwnnwwyfwwddssjhuppvvmmvvfjdczgkkhuutrjffyvvggvvzfhhhzzaddcczqjxifekxxhpggracllvvivccllppxbthjulrqqggxjuthamgttvjwwgenhvqggkkqceyyhhdfzlyyieruxcbbqqxxjoouuovcrrjnnesjnddazznmhhecffajppzebbppktfdtkkdendnsqqbbcvccchhrivocnfzzvvooeehqxntbbodfiiklritidapgvnnlbffpuvvfifnaddnyuuuaaed

这哪是什么密码,简直就是乱码,找了半天没找到原因,死马当活医,于是将代码修改如下:

  1. l = len(a)
  2. for i in range(3, l - 3):
  3.     if a[i].islower():
  4.         if a[i + 1].isupper() + a[i - 1].isupper() == 2:
  5.             if a[i + 2].isupper() + a[i - 2].isupper() == 2:
  6.                 if a[i + 3].isupper() + a[i - 3].isupper() == 2:
  7.                     if a[i + 4].isupper() + a[i - 4].isupper() == 0: 
  8.                         print(a[i], end = '')


结果如下:

  1. ilovefishc
哇噻!竟然对了,这到底是为什么呢?前后代码差不多啊,第一个代码相对简洁啊!为什么就不对呢?
 
经过仔细研究,终于找到原因了,这段代码的问题在于条件只满足了两个条件:
1.小写字母前后的第4个为小写字母
2.小写字母前后的第j个为大写字母
应该改为小写字母前后的3个都为大写字母,直接上代码:
  1. l = len(a)
  2. x = 0
  3. for i in range(3, l - 3):
  4.     if a[i].islower():
  5.         if a[i + 4].isupper() + a[i - 4].isupper() == 0:
  6.             for j in range(1, 4):
  7.                 if a[i + j].isupper() + a[i - j].isupper() == 2:
  8.                     x = 1
  9.                 else:
  10.                     x = 0
  11.                     break
  12.             if x == 1:
  13.                 print(a[i], end = '')

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:python-正则表达式语法规范与案例

下一篇:【leetcode 简单】 第八十八题 猜数字大小