我正在 Python 上创建一个复利程序,它说"TypeError: a float is required".我不知道我做错了什么



Python说程序中需要一个"float":

if selection == 5:
    p5=input("Please enter the principle amount.")
    r5=input("Please enter the rate as a decimal.")
    t5=input("Please enter the number of years you wish to keep the money stored.")
    A=p5*math.e,(r5*t5)
    Ar=round(A,2)
    print "The amount after",t5,"years is",Ar,"."

**是Python中的指数运算符,而不是,

A = p5*math.e**(r5*t5)将给出您正在寻找的整数。

您得到的错误是由于无意中创建的元组(p5*math.e, r5*t5)被传递给round

为了更直接地说明这个问题,round((2.0, 3.0), 2)将给出相同的"TypeError: a float is required",因为(2.0, 3.0)是一个元组。

相关内容

最新更新