Untitled
unknown
python
3 years ago
951 B
4
Indexable
# Define a list of categories categories = ['Housing', 'Food', 'Transportation'] # Define a dictionary to store the user's budget information budget = {} # Initialize the budget for each category to 0 for category in categories: budget[category] = {'income': 0, 'expenses': 0} # Prompt the user to input their budget information for category in categories: income = input(f'Enter the income for {category}: ') expenses = input(f'Enter the expenses for {category}: ') budget[category]['income'] += income budget[category]['expenses'] += expenses # Calculate the overall budget balance balance = 0 for category in categories: balance += budget[category]['income'] - budget[category]['expenses'] # Display the budget balance and breakdown to the user print(f'Your overall budget balance is: {balance}') for category in categories: print(f'{category}: Income = {budget[category]['income']}, Expenses = {budget[category]['expenses']}')
Editor is loading...