Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
| 7 |
-
st.
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
st.
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
-
color: #
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
# Request input for
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
# Request input for the
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
#
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
#
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
st.
|
| 51 |
-
|
| 52 |
-
st.
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 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!*")
|