python结束程序的三种技巧

1. break

2.exit(0)

3.sys.exit(0)

 

 

import file_manager
import sys


def start():
    # try:
    #     with open('file/welcome.txt','r',encoding='utf8') as f:
    #         content = f.read()
    #         while True:
    #             input(content)
    # except FileNotFoundError:
    #     print('文件未找到!')
    content = file_manager.read_file('welcome.txt')
    # file_manager.BASE_DIR = './xxx/'
    # content = file_manager.read_file('sss.txt')
    while True:
        operator = input(content + '\n请输入(1-3:')
        if operator == '1':
            print('注册')
        elif operator == '2':
            print('登录')
        elif operator == '3':
            print('退出')
            # break   # 结束循环
            # exit(0)  # 退出整个程序
            sys.exit(0)  # 退出整个程序
        else:
            print('输入有误!')


if __name__ == '__main__':
    start()

 

posted @ 2021-01-25 12:39  Only-W  阅读(4603)  评论(0编辑  收藏  举报