fork download
  1. import itertools
  2.  
  3. expenses = 0.05
  4. earnings = 0.02
  5. money = 1
  6.  
  7. for year in itertools.count():
  8. print("Year %s: %s%% left" % (year, money * 100))
  9. if money < 0:
  10. break
  11.  
  12. # We'll be generous and assume that you get all of your yearly income
  13. # before paying for any expenses.
  14. money += money * earnings
  15.  
  16. # Note that expenses are a fixed cost, not a percentage.
  17. money -= expenses
Success #stdin #stdout 0.02s 8688KB
stdin
Standard input is empty
stdout
Year 0: 100% left
Year 1: 97.0% left
Year 2: 93.93999999999998% left
Year 3: 90.81879999999998% left
Year 4: 87.63517599999999% left
Year 5: 84.38787951999997% left
Year 6: 81.07563711039997% left
Year 7: 77.69714985260796% left
Year 8: 74.25109284966011% left
Year 9: 70.73611470665332% left
Year 10: 67.15083700078638% left
Year 11: 63.493853740802095% left
Year 12: 59.76373081561813% left
Year 13: 55.959005431930485% left
Year 14: 52.07818554056909% left
Year 15: 48.11974925138047% left
Year 16: 44.08214423640808% left
Year 17: 39.96378712113624% left
Year 18: 35.763062863558964% left
Year 19: 31.47832412083014% left
Year 20: 27.107890603246748% left
Year 21: 22.650048415311687% left
Year 22: 18.10304938361792% left
Year 23: 13.46511037129028% left
Year 24: 8.734412578716084% left
Year 25: 3.909100830290406% left
Year 26: -1.0127171531037864% left