我正在为《人物401k》设计一个财务模型,它使用等式中每年的随机回报率。我想知道在循环过程中,如何使回报率从一个变化到下一个。换句话说,我想要一个随机的回报率,每次计算蜡球时都要用到。在
例如, 第一年2000*1.10=2200 第二年2100*1.2=2520*
*这不包括“我的代码”中的wax_nu-ball&contribution变量。我的问题似乎是与选择功能…我有它进口来选择3个不同的回报率。在
下面是我的代码。在
谢谢你的帮助。 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
print "How much do you want to contribute to your 401k?"
contribution = int(raw_input())
# money contributed to 401k
print "What is your 401k worth now?"
wax_ball = int(raw_input())
# sum of all contribution plus interest of every year
print "When do you want to withdraw on it?"
time= int(raw_input())
# time in years
interest_rate = [.25,.1,.01]
#average return rate randomized
from random import choice
choice(interest_rate)
for x in range (0, time):
wax_ball= contribution+(wax_ball*(1+interest_rate))
print round(wax_ball,2)
如果要为循环的每次迭代使用不同的速率,可以使用:
相关问题 更多 >
编程相关推荐