Program Overview
When buying a house, several factors must be considered, including the annual fuel cost and yearly tax rate.
This Python program calculates the total one-year cost of owning a house based on:
- House price
- Annual fuel cost
- Annual tax
The program continues to accept inputs until the user enters 9999 as the house price.
Python Code:
while True:
price = int(input("Enter house price (9999 to exit): "))
if price == 9999:
break
fuel_cost = float(input("Enter annual fuel cost: "))
tax = float(input("Enter annual tax: "))
total_cost = price + fuel_cost + tax
print(f"Total one-year cost of the house: {total_cost:.2f}\n")Sample Output:
Enter house price (9999 to exit): 1200000
Enter annual fuel cost: 45000
Enter annual tax: 30000
Total one-year cost of the house: 1275000.00
Enter house price (9999 to exit): 9999 Step-by-Step Explanation:
- The program runs in a loop until the user enters 9999 as the house price
- For each entry, it reads the fuel cost and tax
- It calculates the total cost for one year using total = price + fuel + tax
- The result is displayed with two decimal places