sys.exit()为什么不终止脚本

时间:2019-07-03 06:14:30

标签: python python-3.x

当键入NO或N时,文件一直保持运行状态,为什么?

<asp:CheckBoxList ID="tolgraph" runat="server" RepeatLayout="Table" CssClass="cb" RepeatDirection="Horizontal">
    <asp:ListItem Text="Column" Value="column"></asp:ListItem>
    <asp:ListItem Text="Line" Value="line"></asp:ListItem>
    <asp:ListItem Text="Bar" Value="bar"></asp:ListItem>
    <asp:ListItem Text="Pie" Value="pie"></asp:ListItem>
    <asp:ListItem Text="Radar" Value="Radar"></asp:ListItem>
    <asp:ListItem Text="Pareto" Value="Pareto"></asp:ListItem>
</asp:CheckBoxList>

tolgraph.Items.FindByText("Column").Selected = true;

1 个答案:

答案 0 :(得分:1)

您的或陈述不正确的or y将始终为真,请尝试以下操作:

import sys

while True:
    game_choice = str(input('Do you want to play? ')).lower()
    if game_choice == 'yes' or game_choice == 'y':
        print("yes")
        break
    elif game_choice == 'no' or game_choice == 'n':
        sys.exit()
    else:
        print('Please answer only Yes/y or No/n')
        continue

或更好的版本:

import sys

while True:
    game_choice = str(input('Do you want to play? ')).lower()
    if game_choice in ['yes', 'y']:
        print("yes")
        break
    elif game_choice in ['no', 'n']:
        sys.exit()
    else:
        print('Please answer only Yes/y or No/n')
        continue