您好我想循环我的程序,以便一旦它遇到异常,它就会从头开始重启!
>>> while True:
... try:
... x = int(raw_input("Please enter a number: "))
... break
... except ValueError:
... print "Oops! That was no valid number. Try again..."
我该怎么做
答案 0 :(得分:0)
您想删除break
声明中的try
。它告诉python退出while循环。
try:
x = int(raw_input("Please enter a number: "))
except ValueError:
print "Oops! That was no valid number. Try again..."