This Python program reads the price of a product from the previous year and the current year.
It calculates the inflation rate based on the price change and then predicts the price for the next year using the same rate.
The code is formatted for smooth integration into a webpage using the specified HTML structure.
previous_price = float(input("Please enter the product price from last year: "))
current_price = float(input("Please enter the product price from this year: "))
inflation_rate = (current_price - previous_price) / previous_price
next_year_price = current_price * (1 + inflation_rate)
print("Inflation rate:", inflation_rate * 100, "%")
print("Predicted price for next year:", next_year_price)
Please enter the product price from last year: 50000
Please enter the product price from this year: 60000
Inflation rate: 20.0 %
Predicted price for next year: 72000.0
Here’s how the program works:
- It calculates the inflation rate using the formula:
(current price - previous price) ÷ previous price
- It then predicts next year’s price using:
current price × (1 + inflation rate)
- The results are displayed using the print()
function