zoukankan      html  css  js  c++  java
  • 【Python基础】我的第一个 python 程序

    这个python 程序,只是一个空壳,可以用来进行简单的交互测试。

    import sys,shelve
    
    def enter_cmd():
        cmd = input('Please enter the cmd(? for help): ')
        cmd = cmd.strip().lower()
    
        return cmd
    
    def print_help():
        '存储(增加)、查找、更新(修改)、循环打印、删除、退出、帮助'
        print('The available commons are: ')
        print('quit     : Save changes and exit')
        print('?        : Print this message')
    
    
    def main():
        database = shelve.open('database20210915001.dat', writeback=True)
        try:
            while True:
                cmd = enter_cmd()
                if cmd == '?':
                    print_help()
                elif cmd == 'coordinate':
                    enter_coordinate()
                elif cmd == 'quit':
                    return
        finally:
            database.close()
    
    if __name__=='__main__':
      main()

    运行方法:

    上述代码保存在 与 python.exe 同目录下,命名为 MyWorld000.py

    点击 python.exe ,在>>> 提示符,输入 import MyWorld000

    然后再在 >>> 提示符,输入 MyWorld000.main 即可。

    运行结果:

    >>> MyWorld000.main()
    Please enter the cmd(? for help): ?
    The available commons are:
    quit     : Save changes and exit
    ?        : Print this message
    Please enter the cmd(? for help): quit
    >>>

    输入 quit 后,退出。

  • 相关阅读:
    函数的对称性及其图像变换
    KMP 字符串匹配
    15 保护模式中的特权级(上)
    每日总结
    每日总结
    每日总结
    每日总结
    每日总结
    每日总结
    2-26安卓自学
  • 原文地址:https://www.cnblogs.com/gaojian/p/15270604.html
Copyright © 2011-2022 走看看