我想知道 Jupyter Notebook 是否有一个命令,可以在发出命令后停止后续单元格的运行。
I found this question and tried sys.exit() but some of the cells below the command are still being executed.
The structure of my script looks as follows:
# tons of cells above
Run Code Online (Sandbox Code Playgroud)
if df["target"].mean() == 1:
sys.exit("Condition met. Do not execute the cells below.")
Run Code Online (Sandbox Code Playgroud)
# tons of cells below
Run Code Online (Sandbox Code Playgroud)
Ideally, none of the cells represented by tons of cells below should be executed if df["target"].mean() is 1. Otherwise, I do want to the subsequent cells …
我正在尝试制作一个简短的程序,它将返回一个数字的阶乘,这很好.我遇到的唯一问题是如果用户输入非整数值,程序将结束.
num = input("input your number to be factorialised here!: ")
try:
num1 = int(num)
except ValueError:
print("That's not a number!")
if num1 < 0:
print("You can't factorialise a negative number")
elif num1 == 0:
print("the factorial of 0 is 1")
else:
for i in range(1,num1+1):
ans = ans * i
print("the factorial of", num, "is", ans)
Run Code Online (Sandbox Code Playgroud)