-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
39 lines (31 loc) · 1.15 KB
/
app.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
from flask import Flask, request, jsonify, render_template
app = Flask(__name__)
def calculate_loan_details (amount, annual_rate, years):
monthly_rate = annual_rate/100/12
installments = years * 12
if monthly_rate == 0:
#return amount / installments
monthly_payment = amount / installments
else:
#return amount *monthly_rate / (1 (1 + monthly_rate)** -installments)
monthly_payment = amount * monthly_rate / (1 - (1 + monthly_rate) ** -installments)
total_payment = monthly_payment * installments
total_interest = total_payment - amount
return {
'monthly_payment': monthly_payment,
'total_interest': total_interest,
'total_payment': total_payment
}
@app.route('/')
def index():
return render_template ('index1.html')
@app.route('/calculate', methods=['POST'])
def calculate():
data = request.get_json()
amount = float(data['amount'])
annual_rate = float(data['annual_rate'])
years = int(data['years'])
loan_details = calculate_loan_details(amount,annual_rate,years)
return jsonify(loan_details)
if __name__ == '__main__':
app.run(debug=True)