小编Aam*_*mri的帖子

安全地评估简单的字符串方程式

我正在编写一个程序,其中将方程式作为字符串输入,然后求值。到目前为止,我已经提出了:

test_24_string = str(input("Enter your answer: "))
test_24 = eval(test_24_string)
Run Code Online (Sandbox Code Playgroud)

我既需要此方程式的字符串版本,也需要评估的版本。但是,这eval是非常危险的功能。int()但是,使用不起作用,因为这是一个方程式。是否存在一个Python函数,该函数将评估字符串中的数学表达式,就像输入数字一样?

python string equation python-3.x

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

标签 统计

equation ×1

python ×1

python-3.x ×1

string ×1