• python的代码检查


    #!/bin/python3.4
    # coding=utf-8

    class lexicon(object):
    # direction = ['north', 'south', 'east', 'west']
    # verb = ['go', 'stop', 'kill', 'eat']
    # noun = ['door', 'bear', 'princess', 'cabinet']
    # num = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
    # wordtypelist = [direction, verb, noun, num]
    def __init__(self, name):
    self.name = name
    print "Class name is %s." %self.name

    def scan(elements):
    direction = ['north', 'south', 'east', 'west']
    verb = ['go', 'stop', 'kill', 'eat']
    noun = ['door', 'bear', 'princess', 'cabinet']
    num = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
    wordtypelist = [direction, verb, noun, num]

    elements = raw_input(">> ")
    element = elements.split()
    for i in range(len(elements)):
    count = i
    if element in wordtypelist[0]:
    print("num: %d type: %s element: %s" % (count, wordtypelist[0], element))
    elif element in wordtypelist[1]:
    print("num: %d type: %s element: %s" % (count, wordtypelist[1], element))
    elif element in wordtypelist[2]:
    print("num: %d type: %s element: %s" % (count, wordtypelist[2], element))
    else:
    print("num: %d type: %s element: %s" % (count, wordtypelist[3], element))


    if __name__ == '__main__':
    print("##### Start #####")
    stuff = lexicon("lexicon")
    stuff.scan()
    print("##### End #####")


    #!/bin/python3.4
    # coding=utf-8

    class lexicon(object):
    # direction = ['north', 'south', 'east', 'west']
    # verb = ['go', 'stop', 'kill', 'eat']
    # noun = ['door', 'bear', 'princess', 'cabinet']
    # num = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
    # wordtypelist = [direction, verb, noun, num]
    def __init__(self, name):
    self.name = name
    print "Class name is %s." %self.name

    def scan(elements):
    direction = ['north', 'south', 'east', 'west']
    verb = ['go', 'stop', 'kill', 'eat']
    noun = ['door', 'bear', 'princess', 'cabinet']
    num = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
    wordtypelist = [direction, verb, noun, num]

    elements = raw_input(">> ")
    element = elements.split()
    for i in range(len(elements)):
    count = i
    if element in wordtypelist[0]:
    print("num: %d type: %s element: %s" % (count, wordtypelist[0], element))
    elif element in wordtypelist[1]:
    print("num: %d type: %s element: %s" % (count, wordtypelist[1], element))
    elif element in wordtypelist[2]:
    print("num: %d type: %s element: %s" % (count, wordtypelist[2], element))
    else:
    print("num: %d type: %s element: %s" % (count, wordtypelist[3], element))


    if __name__ == '__main__':
    print("##### Start #####")
    stuff = lexicon("lexicon")
    stuff.scan()
    print("##### End #####")




    执行结果:
    [root@localhost conwayGame.py]# python ex48.py
    ##### Start #####
    Class name is lexicon.
    >> eat the python
    num: 0 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: ['eat', 'the', 'python']
    num: 1 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: ['eat', 'the', 'python']
    num: 2 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: ['eat', 'the', 'python']
    num: 3 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: ['eat', 'the', 'python']
    num: 4 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: ['eat', 'the', 'python']
    num: 5 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: ['eat', 'the', 'python']
    num: 6 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: ['eat', 'the', 'python']
    num: 7 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: ['eat', 'the', 'python']
    num: 8 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: ['eat', 'the', 'python']
    num: 9 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: ['eat', 'the', 'python']
    num: 10 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: ['eat', 'the', 'python']
    num: 11 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: ['eat', 'the', 'python']
    num: 12 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: ['eat', 'the', 'python']
    num: 13 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: ['eat', 'the', 'python']
    ##### End #####


     
  • 相关阅读:
    禁止修改的消息首部
    文章详情列表接口 小程序及 模拟器 条数 错误 浏览器正确 调大mysql 查询超时时间 同一接口,小程序环境的TTFB相比浏览器约大5倍。
    七牛云霍锴:实时音视频 SDK 设计实践
    java网页数据抓取
    IDEA properties文件中文自动转为ASCII码(properties输入中文乱码问题)
    阿里官方Java代码规范标准《阿里巴巴Java开发手册 终极版 v1.3.0》下载
    从零开始配置Ubuntu20.04 amd64 virtualenvwarapper angr环境 并做ais3_crackme的CFG图
    请求被中止: 未能创建 SSL/TLS 安全通道 解决方案
    Docker
    爬虫
  • 原文地址:https://www.cnblogs.com/noxy/p/6402443.html
Copyright © 2020-2023  润新知