使用我的基本兴趣计算器,我不断收到错误
r = int(raw_input("What is the rate of growth?\n=> "))
ValueError: invalid literal for int() with base 10: '.52'
我使用的数字是20,000的本金率52%(.052是我投入的)复合是每半年有3个期间
import math
p = int(raw_input("what is the principal value?\n=> "))
r = int(raw_input("What is the rate of growth?\n=> "))
c = int(raw_input("How many compoundings per periods are taking place?
\n=> "))
t = int(raw_input("How mant periods are taking place?\n=> "))
number = str(p*(1+r/c)**c*t)
print(number)
编辑:抱歉蹩脚的变量,这就是我的作业;)
如果你想要浮点数,为什么要将输入字符串转换为int
?
更改
r = int(raw_input("What is the rate of growth?\n=> "))
至
r = float(raw_input("What is the rate of growth?\n=> "))
没有;这是一个矛盾:int
没有小数点。 .052
不是int;这是一个浮动。使用正确的转换:
rate = float(raw_input("What is the rate of growth?\n=> "))
另外,使用有意义的变量名称;单字母变量往往会联合起来并在以后咬你。