write a code that will take in the initial ammount and years as iunput as numerical value and then put it into a formula: initial ammount x (0.20+1)^years. Then you also tell me the monthly earning by calculating profit (final amount minus intial ammount) divide by yeaRS divide by 12
To upload files, please first save the app
import streamlit as st
st.title("Investment Calculator")
# Get user input
initial_amount = st.number_input("Enter initial investment amount (PKR)", min_value=0.0, value=1000.0)
years = st.number_input("Enter number of years", min_value=1, value=5)
# Calculate final amount using the formula: initial_amount × (1.20)^years
interest_rate = 0.20
final_amount = initial_amount * ((1 + interest_rate) ** years)
# Calculate total profit
total_profit = final_amount - initial_amount
# Calculate monthly earnings
monthly_earnings = total_profit / (years * 12)
# Display results
st.write("---")
st.write("### Results")
st.write(f"Initial Investment: PKR{initial_amount:,.2f}")
st.write(f"Investment Period: {years} years")
st.write(f"Final Amount: PKR{final_amount:,.2f}")
st.write(f"Total Profit: PKR{total_profit:,.2f}")
st.write(f"Monthly Earnings: PKR{monthly_earnings:,.2f}")
# Add explanation
st.write("---")
st.write("### How it works")
st.write("""
This calculator uses the compound interest formula with a 20% annual return rate:
- Final Amount = Initial Amount × (1 + 0.20)^Years
- Total Profit = Final Amount - Initial Amount
- Monthly Earnings = Total Profit ÷ (Years × 12)
""")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?