Python Program to Calculate a Discount
Beginner · Basics
A discount takes a percentage off the marked price of an item. For a 20% discount on Rs 2500, the discount is 2500 x 20 / 100 = Rs 500, so you pay Rs 2000, and this program works out both amounts.
Program
Marked price: Rs 2500.00 Discount (20%): Rs 500.00 Price to pay: Rs 2000.00
How it works
- A percentage means "out of 100", so the discount is
marked_price * discount_percent / 100. - Taking the discount away from the marked price gives the price to pay.
:.2fshows the amounts in rupees and paise, with two decimal places.
Other ways to write it
A discount that depends on the bill
Bill: Rs 4200, discount 10%: Rs 420.00 Amount to pay: Rs 3780.00
Shops often give a bigger discount on a bigger bill. The elif chain checks the largest bill first, so each bill gets the best rate it qualifies for.
Two discounts, one after the other
After 20% off: Rs 800.00 After a further 10% off: Rs 720.00 Overall discount: 28%, not 30%
The second discount is taken from the already reduced price, so 20% and then 10% comes to 28% in total, not 30%.
Try it yourself
Add 18% GST to the discounted price and print the final amount to pay.
Edit the program above and press Run, or open it in the full editor to save it and share it. To watch it run line by line, open it in the visualizer.
Related programs
All Python programs · CBSE class 12 practical file · Python exercises