Build a web application (preferably STREAMLIT) that compares the following options: Option A: Leasing a car from work Option B: Buying a car Option C: Operational leasing Show the different options after they fill out a short form: Name: _; Type of vehicle: Family car not older than 2020; Financing capabilities: _ shekels; Km per year: _ Show: (CHECKBOX) Leasing vehicle | Buying a car | Operational leasing For each option, show cost for buying, leasing and Operational leasing respectively: Test + treatments yearly costs: 5000, 0, 1800; Financing costs yearly costs: max(0, (100000-Financing capabilities)) * 10%, 0, 0; Monthly payment: 0, 4500, 2650 Initial payment: 100000, 0, 1900; Insurance yearly costs: 5000, 0, 0 impairment loss yearly costs: 100000*11%, 0, 0; Fuel yearly costs: “Km per year” * 7.5/17, 0, “Km per year” * 7.5/17; Total yearly costs: Test + treatments yearly costs + Financing costs + Insurance yearly costs + impairment loss yearly costs + Fuel yearly costs
To upload files, please first save the app
import streamlit as st
import pandas as pd
import numpy as np
st.title("Car Cost Comparison Calculator")
# Initialize form inputs
with st.form("car_form"):
name = st.text_input("Name")
vehicle_type = st.selectbox(
"Type of vehicle",
["Family car not older than 2020"],
disabled=True
)
financing_capabilities = st.number_input("Financing capabilities (in shekels)", min_value=0, value=50000)
km_per_year = st.number_input("Kilometers per year", min_value=0, value=20000)
# Checkboxes for comparison
col1, col2, col3 = st.columns(3)
with col1:
show_leasing = st.checkbox("Leasing vehicle", value=True)
with col2:
show_buying = st.checkbox("Buying a car", value=True)
with col3:
show_operational = st.checkbox("Operational leasing", value=True)
submitted = st.form_submit_button("Calculate")
if submitted:
# Calculate costs for each option
options = []
costs = []
if show_leasing:
# Option A: Leasing from work
test_treatment = 5000
financing = max(0, (100000-financing_capabilities)) * 0.10
monthly = 0
initial = 100000
insurance = 5000
impairment = 100000 * 0.11
fuel = km_per_year * 7.5/17
total = test_treatment + financing + (monthly * 12) + insurance + impairment + fuel
options.append("Leasing from work")
costs.append({
"Test & Treatments (yearly)": test_treatment,
"Financing (yearly)": financing,
"Monthly Payment": monthly,
"Initial Payment": initial,
"Insurance (yearly)": insurance,
"Impairment Loss (yearly)": impairment,
"Fuel (yearly)": fuel,
"Total Yearly Costs": total
})
if show_buying:
# Option B: Buying a car
options.append("Buying a car")
costs.append({
"Test & Treatments (yearly)": 0,
"Financing (yearly)": 0,
"Monthly Payment": 4500,
"Initial Payment": 0,
"Insurance (yearly)": 0,
"Impairment Loss (yearly)": 0,
"Fuel (yearly)": 0,
"Total Yearly Costs": 4500 * 12
})
if show_operational:
# Option C: Operational leasing
test_treatment = 1800
financing = 0
monthly = 2650
initial = 1900
insurance = 0
impairment = 0
fuel = km_per_year * 7.5/17
total = test_treatment + financing + (monthly * 12) + insurance + impairment + fuel
options.append("Operational leasing")
costs.append({
"Test & Treatments (yearly)": test_treatment,
"Financing (yearly)": financing,
"Monthly Payment": monthly,
"Initial Payment": initial,
"Insurance (yearly)": insurance,
"Impairment Loss (yearly)": impairment,
"Fuel (yearly)": fuel,
"Total Yearly Costs": total
})
# Create comparison DataFrame
df = pd.DataFrame(costs, index=options)
# Display results
st.header("Cost Comparison")
st.dataframe(df.style.format("{:.2f}"))
# Create bar chart for total yearly costs
st.header("Total Yearly Costs Comparison")
st.bar_chart(df["Total Yearly Costs"])
# Show additional insights
st.header("Analysis")
min_cost_option = df["Total Yearly Costs"].idxmin()
st.write(f"The most cost-effective option is: **{min_cost_option}**")
# Calculate and display 5-year total cost
five_year_costs = df["Total Yearly Costs"] * 5 + df["Initial Payment"]
st.header("5-Year Total Cost Comparison")
st.dataframe(five_year_costs.to_frame("5-Year Total Cost").style.format("{:.2f}"))
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?