Part of the series

Several example codes

~1 min read • Updated Sep 16, 2025

Program Overview

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.

Python Code:


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)

Sample Output:


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

Explanation:

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


Written & researched by Dr. Shahin Siami