我有一个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时,我无法使其中断。
答案 0 :(得分:2)
response = input('That Ticker does not exist. Try Again? Type exit to quit')
if response.lower() == "exit":
break
您只是在“出口”一词旁边缺少引号