-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemi.py
50 lines (39 loc) · 1.21 KB
/
emi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import sys
import re
import math
if __name__ == '__main__':
if len(sys.argv) != 5:
print("emi.py <emi_type flat/rbm> <interest_rate flat(f)/monthly(m)/yearlly(m)> <borrowed money> <time month(m)/year(m)>")
print("eg. python emi.py flat/rbm 1.0m/12.0y 12000 6m/20y")
exit(0)
emi_type = sys.argv[1]
rate = sys.argv[2]
principal = sys.argv[3]
time = sys.argv[4]
if emi_type not in ['flat', 'rbm']:
print("please mention correct emi_type")
exit(0)
if bool(re.match('^[1-9][0-9]?\.[0-9][myf]$', rate)) == False:
print("please mention correct interest rate")
exit(0)
if bool(re.match('(^([1-9]|1[0-2])m$)|(^[1-9][0-9]?y$)', time)) == False:
print("please mention correct time")
exit(0)
P = int(principal)
# duration in month
if time[-1] == 'y':
N = int(time[:-1])*12
else:
N = int(time[:-1])
R = float(rate[:-1])
if rate[-1] == 'y':
R = (R/(12*100))
else:
R = R/100
if emi_type == 'flat':
emi = (P + R*P) / N
if emi_type == 'rbm':
emi = P*R*(pow((1+R),N)/(pow((1+R),N)-1))
print("monthly emi : {}".format(int(math.floor(emi))))
print("interest paid : {}".format(int(math.ceil(emi*N - P))))
print("total amount paid : {} in {} month".format(int(math.ceil(emi * N)), N))