Part of the series

Several example codes

~1 min read • Updated Oct 12, 2025

Program Overview

This Python program receives the price of a product and a discount percentage.
It sends these values to a method that calculates the discount amount and returns it.
The program then displays the calculated discount.


Python Code:


def calculate_discount(price: float, percent: float) -> float:
    return price * percent / 100

# Read inputs from user
price = float(input("Enter product price: "))
percent = float(input("Enter discount percentage: "))

discount = calculate_discount(price, percent)
print(f"Discount amount: {discount:.2f} units")

Sample Output (input: price = 200000, percent = 15):


Discount amount: 30000.00 units

Step-by-Step Explanation:

- The user enters the product price and discount percentage
- These values are passed to a method that calculates the discount
- The method returns the result, which is displayed with two decimal places


Written & researched by Dr. Shahin Siami