美文网首页
c05ex12.py

c05ex12.py

作者: 特丽斯纳普 | 来源:发表于2018-03-30 20:34 被阅读0次
# c05ex12.py
#    Future value with formatted table.

def main():
    print("This program calculates the future value of an investment.")
    print()
    
    principal = float(input("Enter the initial principal: "))
    apr = float(input("Enter the annualized interest rate: "))
    years = int(input("Enter the number of years: "))

    print("Year   Value")
    print("--------------")
    for i in range(years+1):
        print("{0:3}   ${1:7.2f}".format(i, principal))
        principal = principal * (1 + apr)

main()

相关文章

网友评论

      本文标题:c05ex12.py

      本文链接:https://www.haomeiwen.com/subject/dhqwcftx.html