计算需要您的钱在输入利息的银行中复制多少年

时间:2015-10-10 16:32:07

标签: python-2.7

def inversio(interes_fix_anual):
    interes_fix_anual=float(interes_fix_anual)
    money = input('Write here your credit ')
    interes = interes_fix_anual/100
    years = 0
    while money <= money*2:
        inversion = money+money*interes
        years = years+1
    return years

我检查了很长时间的程序,我没有发现错误,有人可以教我吗?感谢

1 个答案:

答案 0 :(得分:0)

有几个问题。看到结果后,取出print语句。

>>> def inversio(interes_fix_anual):
...     interes_fix_anual=float(interes_fix_anual)
...     money = input('Write here your credit ')
...     interes = interes_fix_anual / 100.0
...     years = 0
...     inversion = money
...     while inversion <= (money * 2):
...         inversion = inversion + (inversion * interes)
...         years = years+1
...         print 'money=' + str(money) + ' inversion=' + str(inversion) + ' years=' + str(years)
...     return years
...
>>> inversio(4)
Write here your credit 100
money=100 inversion=104.0 years=1
money=100 inversion=108.16 years=2
money=100 inversion=112.4864 years=3
money=100 inversion=116.985856 years=4
money=100 inversion=121.66529024 years=5
money=100 inversion=126.53190185 years=6
money=100 inversion=131.593177924 years=7
money=100 inversion=136.856905041 years=8
money=100 inversion=142.331181242 years=9
money=100 inversion=148.024428492 years=10
money=100 inversion=153.945405632 years=11
money=100 inversion=160.103221857 years=12
money=100 inversion=166.507350731 years=13
money=100 inversion=173.16764476 years=14
money=100 inversion=180.094350551 years=15
money=100 inversion=187.298124573 years=16
money=100 inversion=194.790049556 years=17
money=100 inversion=202.581651538 years=18
18