0% found this document useful (0 votes)
5 views1 page

# Budget Calculator With Dynamic Error Handling

The document outlines a budget calculator program that prompts users to input their salary and expenses. It includes dynamic error handling to ensure that only numeric values are accepted for both salary and expenses. The program calculates and displays a budget summary, including total expenses and remaining balance, while handling invalid inputs gracefully.

Uploaded by

ChÄndra Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

# Budget Calculator With Dynamic Error Handling

The document outlines a budget calculator program that prompts users to input their salary and expenses. It includes dynamic error handling to ensure that only numeric values are accepted for both salary and expenses. The program calculates and displays a budget summary, including total expenses and remaining balance, while handling invalid inputs gracefully.

Uploaded by

ChÄndra Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

# Budget Calculator with Dynamic Error Handling

try:
salary = int(input("Enter your salary: ")) # Ensuring salary input
is numeric
total_exp = 0 # Initialize total expenses

# Loop for dynamic expense entry


while True:
expense = input("Enter an expense name or type 'done' to finish:
")
if expense.lower() == 'done': # Fixed indentation issue
break # Exit loop when user enters 'done'

amount = input(f"Enter the amount for {expense}: ")

# Validate numeric input


if amount.isdigit():
total_exp += int(amount)
else:
print("Invalid amount! Please enter a numeric value.") #
Error message for non-numeric input

# Calculate remaining balance


remaining_bal = salary - total_exp

# Final budget summary


message = f"\nBudget Summary:\n- Salary: ${salary}\n- Total Expenses:
${total_exp}\n- Remaining Balance: ${remaining_bal}"
print(message)

except ValueError:
print("Error: Please enter a valid number for salary!") # Handles
non-numeric salary input

You might also like