rasmodev commited on
Commit
752ec51
Β·
verified Β·
1 Parent(s): 5b74b31

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -58
app.py CHANGED
@@ -1,59 +1,56 @@
1
- import streamlit as st
2
-
3
- # Set the title of the app
4
- st.set_page_config(page_title="Mortgage Calculator", page_icon="🏑", layout="centered")
5
-
6
- # Add a header image
7
- st.image("https://thumbs.dreamstime.com/b/d-house-budget-concept-render-56759583.jpg", use_column_width=True)
8
-
9
- # Add a title and a subtitle
10
- st.title("🏑 Mortgage Calculator")
11
- st.write("Calculate your monthly payments and total cost of your mortgage with ease!")
12
-
13
- # Customize with some styling
14
- st.markdown("""
15
- <style>
16
- .main {
17
- background-color: #f5f5f5;
18
- }
19
- h1 {
20
- color: #FF6347;
21
- }
22
- .stButton button {
23
- background-color: #4CAF50;
24
- color: white;
25
- border-radius: 8px;
26
- font-size: 18px;
27
- }
28
- </style>
29
- """, unsafe_allow_html=True)
30
-
31
- # Request input for mortgage loan principal
32
- principal = st.number_input("🏠 Enter the mortgage loan principal ($):", min_value=0.0, format="%.2f")
33
-
34
- # Request input for the annual interest rate
35
- interest_rate = st.number_input("πŸ’΅ Enter the annual interest rate (%):", min_value=0.0, format="%.2f")
36
-
37
- # Request input for the number of years to repay the mortgage
38
- years = st.number_input("⏳ Enter the number of years to repay the mortgage:", min_value=1, step=1)
39
-
40
- # Add a calculate button
41
- if st.button("Calculate"):
42
- # Calculate the monthly repayment
43
- monthly_repayment = principal * (interest_rate / 12 / 100 * (1 + interest_rate / 12 / 100)**(years * 12)) / \
44
- ((1 + interest_rate / 12 / 100)**(years * 12) - 1)
45
-
46
- # Calculate the total amount paid over the life of the mortgage
47
- total_amount = monthly_repayment * years * 12
48
-
49
- # Display the mortgage information to the user
50
- st.success(f"For a {years}-year mortgage loan of $ {principal:,.2f}:")
51
- st.write(f"at an annual interest rate of {interest_rate:.2f}%:")
52
- st.write(f"πŸ’° **Monthly Payment**: $ {monthly_repayment:,.2f}")
53
- st.write(f"πŸ’° **Total Payment**: $ {total_amount:,.2f}")
54
-
55
- st.balloons()
56
-
57
- # Add a footer
58
- st.write("---")
59
  st.write("πŸ’¬ *Thank you for using the Mortgage Calculator!*")
 
1
+ import streamlit as st
2
+
3
+ # Set the title of the app
4
+ st.set_page_config(page_title="Mortgage Calculator", page_icon="🏑", layout="centered")
5
+
6
+ # Add a title and a subtitle
7
+ st.title("🏑 Mortgage Calculator")
8
+ st.write("Calculate your monthly payments and total cost of your mortgage with ease!")
9
+
10
+ # Customize with some styling
11
+ st.markdown("""
12
+ <style>
13
+ .main {
14
+ background-color: #f5f5f5;
15
+ }
16
+ h1 {
17
+ color: #FF6347;
18
+ }
19
+ .stButton button {
20
+ background-color: #4CAF50;
21
+ color: white;
22
+ border-radius: 8px;
23
+ font-size: 18px;
24
+ }
25
+ </style>
26
+ """, unsafe_allow_html=True)
27
+
28
+ # Request input for mortgage loan principal
29
+ principal = st.number_input("🏠 Enter the mortgage loan principal ($):", min_value=0.0, format="%.2f")
30
+
31
+ # Request input for the annual interest rate
32
+ interest_rate = st.number_input("πŸ’΅ Enter the annual interest rate (%):", min_value=0.0, format="%.2f")
33
+
34
+ # Request input for the number of years to repay the mortgage
35
+ years = st.number_input("⏳ Enter the number of years to repay the mortgage:", min_value=1, step=1)
36
+
37
+ # Add a calculate button
38
+ if st.button("Calculate"):
39
+ # Calculate the monthly repayment
40
+ monthly_repayment = principal * (interest_rate / 12 / 100 * (1 + interest_rate / 12 / 100)**(years * 12)) / \
41
+ ((1 + interest_rate / 12 / 100)**(years * 12) - 1)
42
+
43
+ # Calculate the total amount paid over the life of the mortgage
44
+ total_amount = monthly_repayment * years * 12
45
+
46
+ # Display the mortgage information to the user
47
+ st.success(f"For a {years}-year mortgage loan of $ {principal:,.2f}:")
48
+ st.write(f"at an annual interest rate of {interest_rate:.2f}%:")
49
+ st.write(f"πŸ’° **Monthly Payment**: $ {monthly_repayment:,.2f}")
50
+ st.write(f"πŸ’° **Total Payment**: $ {total_amount:,.2f}")
51
+
52
+ st.balloons()
53
+
54
+ # Add a footer
55
+ st.write("---")
 
 
 
56
  st.write("πŸ’¬ *Thank you for using the Mortgage Calculator!*")