The formula to calculate a discount in Python is final_price = price * (1 - discount / 100), where price is the original amount and discount is the percent off as a number (25 for 25%, not 0.25). That single line gives you the sale price; subtracting it from the original price gives the amount you save. For example, $80 at 25% off produces a final price of $60 and savings of $20. To stack multiple coupons, multiply the discount factors one after another: final_price = price * (1 - d1/100) * (1 - d2/100) * ..., which is exactly why 20% off followed by 10% off of $100 lands at $72 rather than $70 — the second coupon only acts on the already-reduced $80, so the effective combined discount is 28% instead of the naive 30%. The same math runs identically in any language because it is plain multiplication; Python's clean syntax makes it a popular teaching example, but you do not actually need code to get the right answer. A browser-based calculator that runs the formula as you type reaches the same number with less friction and zero setup. Below is the Python code for single and stacked discounts, the exact numbers behind the stacking trap, and the faster browser-based alternative when you just want the price.

The Discount Formula in One Line
The math behind any percentage discount is just two operations: convert the percent into a decimal by dividing by 100, then multiply the original price by one minus that decimal. Written as one expression that works identically in Python, JavaScript, a spreadsheet, or on paper: final_price = price × (1 − discount / 100). From there, the amount you save is simply the original price minus the final price: saved = price − final_price. Those two outputs — what you actually pay and what stays in your pocket — are the only numbers a discount calculator needs to display. A 0% discount leaves the price unchanged, and a 100% discount makes it free. Because the formula is a single multiplication, the result is exact up to whatever rounding the display applies at the end, so intermediate values stay clean and only the final answer is rounded to two decimals.
Python: Calculate a Single Discount
In Python, the formula above translates into three readable lines. Here is the simplest working version, assuming you already have a price and a discount value:
price = 80; discount = 25; final_price = price * (1 - discount / 100)
That gives final_price = 60.0. To get the savings, subtract: saved = price - final_price, which yields 20.0. If you want clean currency-style output, wrap each in Python's built-in formatter: print(f"${final_price:.2f}") prints $60.00. Two details that trip beginners up: the discount is expressed as 25, not 0.25, because the formula divides by 100; and Python's division returns a float, so final_price will be 60.0 rather than 60 unless you cast it with int() or round it. For a one-shot check, that is the entire program.
To make it reusable, wrap the body in a function and pass the two numbers in: def discount_price(price, discount): return price * (1 - discount / 100). Calling discount_price(80, 25) returns 60.0, and calling discount_price(120, 15) returns 102.0. That function is the same code behind most production checkout systems; the only difference is the surrounding UI.
Python: Stack Coupons Correctly (and Why 20% + 10% ≠ 30%)
Stacking is where most shoppers — and most beginner code — go wrong. The instinct is to add the percentages: 20% off plus an extra 10% off must be 30% off. It is not, because percentage discounts apply sequentially, each one to the price that remains after the previous cut. The Python version of "apply coupon after coupon" is to multiply the discount factors against a running total: final_price = price; for d in [20, 10]: final_price *= (1 - d / 100). The loop runs the formula once per coupon, each time against the running price, and the list [20, 10] can hold as many percentages as the deal allows. Because multiplication is order-independent, swapping the coupons — running 10% first and 20% second — produces the same final price, since 0.80 × 0.90 equals 0.90 × 0.80. That property is worth remembering when you audit a receipt: a cashier who applied the coupons in reverse order has not made a mistake.
Worked example with $100, 20% off, then 10% off:
Step 1 — apply the first 20% off the original $100: final = 100 × (1 − 20/100) = 100 × 0.80 = $80.
Step 2 — apply the second 10% off that $80: final = 80 × (1 − 10/100) = 80 × 0.90 = $72.
Combined: you pay $72 and save $28. Divide savings by the original price: 28 / 100 = 0.28, so the true effective discount is 28%, not 30%. The 2-percentage-point gap comes from the second coupon only seeing the already-reduced $80, never the original $100. Add a third coupon, say 5%, and the effective rate falls further behind the naive sum because each new percentage acts on a smaller and smaller base.
How to Use the Discount Calculator
For anyone who would rather type numbers into a webpage than run a script, the Discount Calculator performs the same math instantly, with no sign-up and nothing leaving your browser. Three steps cover both single-coupon and stacked-coupon cases:
- Enter the original price and the discount percentage — the final price and amount saved appear instantly as you type.
- To combine coupons, click "Stack another discount" and add each extra percent; discounts apply one after another, not added together.
- Read the final price you pay, the total you save, and (when stacking) the true combined effective discount percentage that you can compare against any single-coupon competitor offer.
Because every calculation runs locally in JavaScript, your inputs never leave your device — useful when comparing a private bulk order or a salary-discounted purchase you would rather not share with a server. The same math as the Python script above runs behind the form, with the running-product formula handling as many stacked coupons as you add.
Python vs. a Browser Calculator
Python is the right tool when you want to learn the formula, batch-process a CSV of prices, or embed discount logic inside a larger checkout system. It is overkill when you are standing in a store with your phone, glancing at a clearance rack, or comparing two coupons at a cashier's counter. A browser tool updates the answer as you type, so there is no "run the script, read the output" loop. For one-off checks — "is this 25%-off-with-extra-10% tag actually beating the competitor's flat 30%?" — the Discount Calculator answers in less time than it takes to open a terminal.
Use Python when the inputs are dynamic and automated (a pricing engine, a bulk reorder script, a test fixture for an e-commerce module). Use the browser tool when the input is a single number you can see and the output is a single number you need to know. Both arrive at the same answer because both run the same formula; the difference is purely about where you are and how often you need to repeat the calculation.
Common Stacking Mistakes Shoppers Make
The single most common error is treating stacked coupons as additive. They are multiplicative. The table below shows how the relationship between "the percentage you expect" and "the percentage you actually get" shifts as you stack more coupons — without quoting computed totals, which you can verify instantly in the tool.
| Stacking Pattern | How the Math Behaves | Expectation vs. Reality |
|---|---|---|
| Single coupon (e.g. 30% off) | One multiplication: final = price × (1 − d/100) | Expectation matches reality exactly |
| Two sequential coupons (e.g. 20% then 10%) | Two multiplications chained on the running price | Shoppers expect the sum; effective rate is below the sum |
| Three or more sequential coupons | Each new percentage acts on a smaller base | Gap between expected sum and effective rate widens with each added coupon |
Beyond the math itself, two practical mistakes appear over and over. First, people read "extra 15% off clearance" as 15% on top of the marked-down price, then compare it naively against a flat 40% sale elsewhere — the effective-rate comparison only works when you fold the extra 15% into the running calculation. Second, people assume the order of stacked coupons matters; it does not, because the final price is the product of all discount factors and multiplication is commutative. If a cashier applied the coupons in a different order than you expected, the receipt is still correct. To check any specific number, type the original price and each percentage into the calculator and read off the combined effective discount directly.