相关疑难解决方法(0)

终止Python脚本

我知道die()PHP 中的命令可以提前停止脚本.

我怎么能用Python做到这一点?

python termination

981
推荐指数
10
解决办法
139万
查看次数

如何在python脚本中暂停执行?

可能重复:以
编程方式停止执行python脚本?
终止Python脚本

我想打印一个值,然后暂停脚本的执行.

我只是使用退货吗?

python

9
推荐指数
3
解决办法
2万
查看次数

一旦满足条件如何停止python程序(在jupyter笔记本中)

我想知道 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 …

python jupyter-notebook

6
推荐指数
1
解决办法
5809
查看次数

提前结束一个程序,而不是循环?

我正在尝试制作一个简短的程序,它将返回一个数字的阶乘,这很好.我遇到的唯一问题是如果用户输入非整数值,程序将结束.

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)

python

5
推荐指数
1
解决办法
142
查看次数

标签 统计

python ×4

jupyter-notebook ×1

termination ×1