# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="view-in-github" colab_type="text"
# <a href="https://colab.research.google.com/github/marprezd/python-lab/blob/master/Basic/budget_analysis.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + [markdown] id="C8DbxTPVeaKs"
# This is a program that asks the user to enter the amount that he or she has budgeted for a month. A loop should then prompt the user to enter each of his or her expenses for the month and keep a running total. When the loop finishes, the program should display the amount that the user is over or under budget.

# + colab={"base_uri": "https://localhost:8080/"} id="FMx6BCg7efTM" outputId="0e3d19ce-5e6e-4436-ce20-f5d91c105a94"
# Initialize variable and centinele
total_spenses = 0.0
expenses = 'y'

# Prompt the user to enter the amount that is budgeted for a month.
monthly_budget = float(input("Enter the amount that budgeted " +
                             "for a month >> "))

# while expenses equal to 'y/Y' loop...
while expenses == 'y' or expenses == 'Y':
    monthly_expense = float(input("Enter some monthly expense >> "))
    total_spenses += monthly_expense
    expenses = input("Is there any other expense to add? Type 'y/Y' " +
                     "to continue or 'n' to get out of the program >> "
                     )

# Display summary header
print()
print("Your summary of the budget and monthly expenses...")
print("------------------------------------------------------------")

# Determine if the user exceeded or not your monthly budget and
# display information
if total_spenses > monthly_budget:
    over_budget = total_spenses - monthly_budget
    print("\tMonthly Budget\tTotal Expenses\tOver Budget")
    print("------------------------------------------------------------")
    print(f"\t${monthly_budget:.2f}\t\t${total_spenses:.2f}" +
          f"\t\t${over_budget:.2f}")
else:
    under_budget = monthly_budget - total_spenses
    print("\tMonthly Budget\tTotal Expenses\tUnder Budget")
    print("------------------------------------------------------------")
    print(f"\t${monthly_budget:.2f}\t\t${total_spenses:.2f}" +
          f"\t\t${under_budget:.2f}")

StarcoderdataJupyterScriptsDedupFiltered