Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
def loan_emi(amount, duration, rate, down_payment=0):
|
3 |
+
"""
|
4 |
+
Calculate the Equated Monthly Installment (EMI) for a loan.
|
5 |
+
|
6 |
+
Parameters:
|
7 |
+
amount (float): Total loan amount (principal).
|
8 |
+
duration (int): Loan duration in months.
|
9 |
+
rate (float): Monthly interest rate (as a decimal, e.g., 0.1 for 10%).
|
10 |
+
down_payment (float, optional): Initial amount paid upfront. Default is 0.
|
11 |
+
|
12 |
+
Returns:
|
13 |
+
float: EMI amount rounded to 2 decimal places.
|
14 |
+
"""
|
15 |
+
loan_amount = amount - down_payment
|
16 |
+
emi = (loan_amount * rate * ((1 + rate) ** duration)) / (((1 + rate) ** duration) - 1)
|
17 |
+
return round(emi, 2)
|
18 |
+
|
19 |
+
# Example usage
|
20 |
+
if __name__ == "__main__":
|
21 |
+
amount = float(input("Enter the loan amount: ")) # Principal amount
|
22 |
+
duration = int(input("Enter the loan duration in months: ")) # Loan duration in months
|
23 |
+
rate = float(input("Enter the monthly interest rate (as decimal, e.g., 0.1 for 10%): ")) # Monthly interest rate
|
24 |
+
down_payment = float(input("Enter the down payment amount (if any, else 0): "))
|
25 |
+
|
26 |
+
emi_value = loan_emi(amount, duration, rate, down_payment)
|
27 |
+
print(f"Monthly EMI: {emi_value}")
|