继之前的出色帮助之后,我现在遇到了异常处理的问题。我有一个 11 个地块的列表,由它们的索引号选择。如果用户选择高于 11,它应该要求他们重新输入,但是 atm,我得到 IndexError: list index out of range。我会认为 except 行只会处理其他任何事情......但它一定只是缺失的一行?
try:
response = raw_input("Select a monitoring plot from the list (0-11): ")
if response == 'q':
confirm = raw_input('Confirm quit (y/ n)...')
if confirm == 'y':
print 'Bye'
break
else:
continue
selected = dataList[int(plotSelect) + 1]
print 'You selected : ', selected[1]
except ValueError:
print "Error: Please enter a number between 0 and 11"