• Python 定位字符串


    一位朋友在玩闯关游戏时遇到如下问题:

    感觉考查的就是字符串操作,用string模块就可完成;代码如下:

    # -*- coding: utf-8 -*-
    
    __author__ = 'Evilxr'
    
    import string
    
    
    _string =("Vm0wd2QyUXlVWGxWV30d4WFlURn164dVRlpzWkc5V"
        "1JteDBaVVYwV0ZKdGVGWlZiVFZyVmxVeFY3yTkljRmhoTVhCU"
        "VZtcEdZV015U2tWVWJHaG9UVlZ3VlZadGNFZFRNbEpJVm10V1"
        "VtSk3lRazlVVkVKTFUFAceB00BxWmtWMXBFVWxwV01ERTBWMn"
        "RvUjFWdF55NsWlhiR2hYWVd0d2RscFdXbUZrUjA1R1drWndWM"
        "DFFUlRGV1ZFb3dWakZhV0ZOcmFHaFNlbXhXVm0weGIxSkdXbG"
        "RYYlVaclVqRmFTRll5TVRSVk1rcElaSHBDVjAxdVVuWldha3B"
        "IWXpGT2RWVnNXbWxoTUhCWl4A4YxWlNSMlF52UmtkWGEyUllZ"
        "bGhT5V0ZSV1pGTk5SbFowWlVaT1ZXSkdjREZWVjNoelZqRmFO"
        "bEZZYUZaaGExcG9WakJhVDJOdFJrZFhiV3hUVFcxb2IxWnRjR"
        "U5pTVVWNFdrVmtXRmRIVWxsWmJHaFRZMVpTVjJGRlRsTmlSbk"
        "JaV2xWYVQxWlhTa2RqUm1oYVRVWktXRll3V21GU2JFNTBZVVp"
        "44rYUdFeGNHOVdha0poVXpGa1dGSnJaR2hTTW1oUFZGY3hiMW"
        "RzV1hoWGJFNVRUVlp3TUZadGRHdFdNa3B6VTIxR1ZWWjZWblp"
        "XUkVaVFZteGtjbHBIY0U1V2EzQlhWbFprTkZNeFRYaFhhMXBQ"
        "VmxacmJFMHdVU1V6UkElM0QlM0Q")
    mark = 0
    while mark < len(_string) - 8:
        # 构造字符串
        result = _string[mark: mark + 8]
        try:
            # 长度为8
            assert len(result) == 8
        except:
            print u'字符串长度不为8'
            break
        try:
            # 它的前两位是大写英文
            assert result[0] in string.ascii_uppercase
            assert result[1] in string.ascii_uppercase
            # 它的3、4位是小写英文
            assert result[2] in string.ascii_lowercase
            assert result[3] in string.ascii_lowercase
            # 它的第5位和第8位是同一个字符
            assert result[4] == result[7]
            # 它的第6、7位是数字
            assert result[5] in string.digits
            assert result[6] in string.digits
    
            print 'success', result
            break
        except:
            mark = mark +1
    

      

     运行结果:

    success FAceB00B
    
  • 相关阅读:
    Navicat加载缓慢
    使用Typora上传博客到博客园
    echart柱状图X轴文字换行
    pc端可以滑动,手机端不能滑动
    select选择最近3年的年份查询
    JQ延时模糊查询
    reset.css
    base64加密
    第四次博客作业结对项目
    WPF DataGrid显示网格 和TImer定时器
  • 原文地址:https://www.cnblogs.com/evilxr/p/4114825.html
Copyright © 2020-2023  润新知