我有我正在编写的这个程序,我希望它退出。
意思是,当我输入Q
或给它一个输入时Q
,它应该向我显示..
Press Q to quit: Q
And it should show >>> in next line
但到目前为止,我有:
list = ['Approval', 'Range', 'Plurality', 'IRV', 'Borda', 'Q']
input_prompt = prompt_from_list('Select a voting system or Q to quit:', list)
while input_prompt != 'Q':
approval_file = open(APPROVAL_BALLOT_FILENAME, 'r')
approval = approval_file.readlines()
approval_file.close()
if input_prompt == 'Approval':
print('Running for Approval')
prompt_riding = prompt_for_riding("Which riding would you like to see results for? (Enter a number between 0 and 307, or all.):",
307)
list = format_approval_list(approval, prompt_riding)
a = vs.voting_approval(list)
country = print_country_results(a[1])
elif input_prompt == 'Range':
print('Running for Range')
prompt_riding = prompt_for_riding("Which riding would you like to see results for? (Enter a number between 0 and 307, or all.):",
307)
print prompt_riding
现在它应该继续循环..在我们输入提示之后它应该转到prompt_riding,但它没有......:(
>>>Select a voting system or Q to quit:
Approval, Range, Plurality, IRV, Borda, Q
Approval
Running for Approval
Which riding would you like to see results for? (Enter a number between 0 and 307, or all.):0
Which riding would you like to see results for? (Enter a number between 0 and 307, or all.):
It should show me..
Select a voting system or Q to quit:
Approval, Range, Plurality, IRV, Borda, Q
有没有一种可能的方法可以关闭无限的while循环?