Sarah has $5000 saved up for her holiday shopping. She plans to buy gifts for her family and make a few purchases for herself. After calculating her expenses, she wants to divide the remaining amount into two parts: personal shopping and savings.
Here’s how to structure the problem:
Initial Setup:
- Define a variable for Sarah’s initial savings and set it to $500.
Input Expenses:
- Ask Sarah how much she spent on a new phone (
phone_cost
). - Ask her how much she spent on clothes (
clothes_cost
). - Ask how much she spent on a book (
book_cost
). - Ask how much she spent on a holiday decoration (
decoration_cost
). - Ask how much she spent on a special dinner (
dinner_cost
).
- Ask Sarah how much she spent on a new phone (
Calculate Remaining Balance:
- Subtract the total expenses (
phone_cost
,clothes_cost
,book_cost
,decoration_cost
,dinner_cost
) from the initial savings. - Store the result in a variable called
remaining_balance
.
- Subtract the total expenses (
Decide Spending and Saving:
- Ask Sarah how much she wants to allocate for personal shopping (
personal_shopping
). - Subtract this amount from the
remaining_balance
. - The rest should automatically go into savings.
- Ask Sarah how much she wants to allocate for personal shopping (
Check Validity:
- Use an
if
condition to ensure Sarah’s spending doesn’t exceed her remaining balance. - If it does, inform her that she needs to reduce her personal shopping amount.
- Otherwise, confirm the split and display the final savings amount.
- Use an
Display Result:
- Use Streamlit’s
st.columns
to display the expenses, remaining balance, and the breakdown between personal shopping and savings.
- Use Streamlit’s