我想在Python上制作一个退休计算器。这没有什么错的语法,但是当我运行下面的程序:“无法处理的类型:int()<str()”
def main():
print("Let me Retire Financial Calculator")
deposit = input("Please input annual deposit in dollars: $")
rate = input ("Please input annual rate in percentage: %")
time = input("How many years until retirement?")
x = 0
value = 0
while (x < time):
x = x + 1
value = (value * rate) + deposit
print("The value of your account after" +str(time) + "years will be $" + str(value))
它告诉我说:
Traceback (most recent call last):
File "/Users/myname/Documents/Let Me Retire.py", line 8, in <module>
while (x < time):
TypeError: unorderable types: int() < str()
任何想法如何,我可以解决这个问题?
好吧我想通了一切。非常感谢您的时间和精力。我真的很感激。非常感谢你的亲切先生。最后一个问题需要解决,即年费率随着时间的推移而下降。例如,如果我以50%的速度在10年内投入500美元,那么在一年后555.0,555.55,555.5555等会给我550美元......因为它实际上并没有每年执行50%。 – user2074050 2013-02-15 01:22:12
@ user2074050这只是一个数学错误。您正在增加存款,而不是现在的价值。你想'价值* =(1 +利率)'(乘以去年的价值乘以加1)。 – 2013-02-15 02:11:30