python找钱程序_python小程序--计算现值工具

1 #! /usr/bin/env python

2 #-*- coding:utf-8 -*-

3 #Author Ian Ying

4 #

5

6

import sys, math

import argparse

def main(type, years, money, rate):

if type == "future_each":

rate_t = (rate / 100) + 1

pow_v = math.pow(rate_t, years)

total = (1 - pow_v)/(1 - rate_t)

total_v = money * total

pow_v_p = math.pow(rate_t, years - 1)

total_v_p = total_v/ pow_v_p

print("In the %s year, Future money is %s" % (years, total_v))

print("Ex: years =2 . You cash is %s + (%s * %s) = %s" % (money, money, rate_t, total_v))

print("%s Present worth is %s" % (total_v, total_v_p))

elif type == "present_each":

rate_t = (rate / 100) + 1

pow_v = math.pow(rate_t, years)

total = ((pow_v - 1) * rate_t)/((rate_t - 1) * pow_v)

total_v = money * total

print("In the %s year, Present money is %s" % (years, total_v))

print("Ex: years =%s . You cash is %s + (%s / %s) = %s" % (years, money, money, rate_t, total_v))

elif type == "present_one":

rate_t = (rate / 100) + 1

pow_v = math.pow(rate_t, years)

total = pow_v

total_v = money / total

print("%s years later, Present money is %s" % (years, total_v))

elif type == "future_one":

rate_t = (rate / 100) + 1

pow_v = math.pow(rate_t, years)

total = pow_v

total_v = money * total

print("In %s year later , Future money is %s" % (years, total_v))

return 1

if __name__ == '__main__':

parser = argparse.ArgumentParser(description="used for computing money future value or present value.")

parser.add_argument("-t", "--type", choices=["future_each", "present_each", "future_one", "present_one"], help="choose the type for computing.")

parser.add_argument("-y", "--years", type=float, help="input how many years.")

parser.add_argument("-m", "--money", type=float, help="input how much money for one year.")

parser.add_argument("-r", "--rate", type=float, help="input the rate for the every year. unit is %")

args = parser.parse_args()

main(args.type, args.years, args.money, args.rate)

print("Successful done")

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值