-
Notifications
You must be signed in to change notification settings - Fork 0
/
emicalc.py
125 lines (99 loc) · 3.82 KB
/
emicalc.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# Mahbub is quite dumb at programming, be patient while reading the code. Contact him in Telegram @linuxhasan
# I welcome your contribution to this piece of junk
## Added input validation, with better error handling
## Added instructions on how to use it
## Added more descriptive errors
## Used fstring
print(
"How to use: \nEnter your EMI total amount, how many months do you want to pay off your EMI in (3,6,12,24,36), interest rate (in percentage), processing fee (in percentage) and minimum processing fee. It will calculate your EMI and your first EMI with processing fee included. \n\nFor example: Enter total amount: 10000 \nIn how many months do you want to pay off: 12, \nWhat is the interest rate in percentage: 11 \nWhat is the processing fee in percentage?: 2.95 \nWhat is the minimum processing fee?: 575. \n\nNote: From processing fee and minimum processing fee, whichever is bigger, will be added to calculation."
)
def Amount():
while True:
amount = input("Enter total amount: ")
try:
amount = float(amount)
if amount > 0:
break
else:
print("Amount must be higher than", amount)
except Exception:
print("Please enter numbers only. Decimals are allowed")
return amount
def EmiMonth():
while True:
emi_month = input("In how many months do you want to pay off?: ")
try:
emi_month = int(emi_month)
if emi_month > 0:
break
else:
print(
"EMI Month should be higher than 0 (usual terms are 3,6,12,24,36 months)"
)
except Exception:
print(
"Please enter integers only (no decimals). For example: 3, and not 3.5"
)
return emi_month
def InterestRate():
while True:
interest_rate = input("What is the interest rate in percentage?: ")
try:
interest_rate = float(interest_rate)
if interest_rate > 0:
break
else:
interest_rate = 0
break
except Exception:
print("Please enter numbers only. Decimals are allowed")
return interest_rate
def ProcessingFee():
while True:
try:
processing_fee = float(input("What is the processing fee in percentage?: "))
if processing_fee > 0:
break
else:
processing_fee = 0
break
except Exception:
print("Please enter numbers only. Decimals are allowed")
return processing_fee
def MinProcFee():
while True:
try:
min_proc_fee = float(input("What is the minimum processing fee?: "))
if min_proc_fee > 0:
break
else:
min_proc_fee = 0
break
except Exception:
print("Please enter numbers only. Decimals are allowed")
return min_proc_fee
def main():
amount = Amount()
emi_month = EmiMonth()
interest_rate = InterestRate()
processing_fee = ProcessingFee()
min_proc_fee = MinProcFee()
if interest_rate == 0:
EMIValue = amount / emi_month
else:
Interest = interest_rate / 12 / 100
EMIValue = (
amount
* Interest
* (1 + Interest) ** emi_month
/ ((1 + Interest) ** emi_month - 1)
)
print(f"Your payable monthly installment is: {EMIValue:,.2f}")
processing_fee_amount = EMIValue / 100 * processing_fee
if processing_fee_amount > min_proc_fee:
EmiWithProcFee = EMIValue + processing_fee_amount
else:
EmiWithProcFee = EMIValue + min_proc_fee
print(f"Your first EMI installment with processing fee will be {EmiWithProcFee:,.2f}")
if __name__ == "__main__":
main()