当使用PySripter之类的程序时,以下代码不能正确...
基本上,输入值必须是,1, 2, 3, 4 or 10
如果它不是这些数字中的任何一个,那么它会让它们重试。
如果他们选择了列表中的数字,那么它将继续到脚本的下一部分。
在PySripter 中,当我运行它时,它会弹出一个框供我输入值,但如果我按下取消或红叉,它会发送“KeyboardInterrupt”异常,但我无法退出脚本/停止脚本运行..
dvalues = [1, 2, 3, 4, 10]
d1 = None
while d1 is None:
try:
d1= int(input("First Value "))
if not d1 in dvalues:
d1= None
print("Can't do this")
except KeyboardInterrupt:
print('Canceled')
continue
else:
pass
有人知道我在做什么错吗?
编辑
新错误,如果在第一个,第二个或任何输入上退出而不是继续,它是否应该退出整个脚本......
tot = int(15)
dvalues = [1, 2, 3, 4, 5, 10]
while tot > int(0):
d1 = None
while d1 is None:
try:
d1 = int(input("First Value"))
if not d1 in dvalues:
d1 = None
else:
print("Fail")
except KeyboardInterrupt:
break
d2 = None
while d2 is None:
try:
d2 = int(input("Second Value"))
if not d2 in dvalues:
d2 = None
else:
print("Fail")
except KeyboardInterrupt:
break
total = d1+d2