Spaces:
Sleeping
Sleeping
File size: 1,987 Bytes
752ec51 39e567c |
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 |
import streamlit as st
# Set the title of the app
st.set_page_config(page_title="Mortgage Calculator", page_icon="π‘", layout="centered")
# Add a title and a subtitle
st.title("π‘ Mortgage Calculator")
st.write("Calculate your monthly payments and total cost of your mortgage with ease!")
# Customize with some styling
st.markdown("""
<style>
.main {
background-color: #f5f5f5;
}
h1 {
color: #FF6347;
}
.stButton button {
background-color: #4CAF50;
color: white;
border-radius: 8px;
font-size: 18px;
}
</style>
""", unsafe_allow_html=True)
# Request input for mortgage loan principal
principal = st.number_input("π Enter the mortgage loan principal ($):", min_value=0.0, format="%.2f")
# Request input for the annual interest rate
interest_rate = st.number_input("π΅ Enter the annual interest rate (%):", min_value=0.0, format="%.2f")
# Request input for the number of years to repay the mortgage
years = st.number_input("β³ Enter the number of years to repay the mortgage:", min_value=1, step=1)
# Add a calculate button
if st.button("Calculate"):
# Calculate the monthly repayment
monthly_repayment = principal * (interest_rate / 12 / 100 * (1 + interest_rate / 12 / 100)**(years * 12)) / \
((1 + interest_rate / 12 / 100)**(years * 12) - 1)
# Calculate the total amount paid over the life of the mortgage
total_amount = monthly_repayment * years * 12
# Display the mortgage information to the user
st.success(f"For a {years}-year mortgage loan of $ {principal:,.2f}:")
st.write(f"at an annual interest rate of {interest_rate:.2f}%:")
st.write(f"π° **Monthly Payment**: $ {monthly_repayment:,.2f}")
st.write(f"π° **Total Payment**: $ {total_amount:,.2f}")
st.balloons()
# Add a footer
st.write("---")
st.write("π¬ *Thank you for using the Mortgage Calculator!*") |