跳出 Try/Except While 循环
Breaking out of Try/Except While Loop
我有一个 while 循环,它检查自动收报机是否存在,如果不存在,它允许用户重试,但同时如果使用类型退出,它将退出程序。这里的代码
ticker = input("Ticker : ")
while True:
try:
web.DataReader(ticker, 'yahoo',start, end)
print('Ticker exists')
except Exception as e:
responce = input('That Ticker does not exist. Try Again? Type exit to quit')
if responce.lower() == exit:
break
else:
pass
当您键入 exit 时,我无法让它中断。
response = input('That Ticker does not exist. Try Again? Type exit to quit')
if response.lower() == "exit":
break
您只是缺少引号 "exit"
我有一个 while 循环,它检查自动收报机是否存在,如果不存在,它允许用户重试,但同时如果使用类型退出,它将退出程序。这里的代码
ticker = input("Ticker : ")
while True:
try:
web.DataReader(ticker, 'yahoo',start, end)
print('Ticker exists')
except Exception as e:
responce = input('That Ticker does not exist. Try Again? Type exit to quit')
if responce.lower() == exit:
break
else:
pass
当您键入 exit 时,我无法让它中断。
response = input('That Ticker does not exist. Try Again? Type exit to quit')
if response.lower() == "exit":
break
您只是缺少引号 "exit"