将功能导入Jupyter笔记本时出现问题



我在.py文件中创建了一个自定义函数,导入后试图在我的Jupyter笔记本中使用它,但我收到了以下错误:

def percentage_change(updated_total,updated_inflation_values):
return ((updated_inflation_values - updated_total) / updated_inflation_values) * 100

TypeError:-:"str"one_answers"str’`的操作数类型不受支持

,我不知道该怎么解决

谢谢

您给出的是str输入,这就是为什么会出现这样的错误。请确保您提供的是int参数。

检查的执行情况

In [74]: percentage_change(10, 100)
Out[74]: 90.0
In [75]: percentage_change('10', '100')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In [75], line 1
----> 1 percentage_change('10', '100')
Cell In [73], line 2, in percentage_change(updated_total, updated_inflation_values)
1 def percentage_change(updated_total,updated_inflation_values):
----> 2     return ((updated_inflation_values - updated_total) / updated_inflation_values) * 100
TypeError: unsupported operand type(s) for -: 'str' and 'str'

最新更新