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")