提问者:小点点

我如何接受Math.exp作为输入并在Python中使用它进行计算呢?


b = float(input('enter b: ') # where I entered math.exp(2) for b
c = b+4

共1个答案

匿名用户

您可以使用eval:

import math

b = eval(input("enter b: ")) # e.g. math.exp(2) as input
c = b + 4
print(c)

请注意,用户可能会输入您不希望计算的表达式。