if条件判断失败,执行else之后,直接退出整个程序

if条件判断失败,执行else之后,直接退出整个程序。

使用sys.exit()

    in_game = input("请输入:剪子、石头、布?")
    if (in_game == "剪子"):
        in_num = 0
    elif (in_game == "石头"):
        in_num = 1
    elif (in_game == "布"):
        in_num = 2
    else:
        print("输入错误!")
        sys.exit()
    computer = random.randint(0,2)
    if ((in_num == 0)and(computer == 0))or((in_num == 1)and(computer == 1))or((in_num == 2)and(computer == 2)):
        print("平局!")
    elif ((in_num == 0)and(computer == 1))or((in_num == 1)and(computer == 2))or((in_num == 2)and(computer == 0)):
        print("你输了!")
    else:
        print("你赢了。")
    print("退出成功了!")
posted @ 2022-03-11 11:03  竹林深深处  阅读(616)  评论(0编辑  收藏  举报