Bill Discount System in Python
Apply different discount slabs based on total bill amount.
BeginnerConditional ProgramsExample 17 of 20
bill-discount-system.py
1# Program for bill discount system23amount = float(input("Enter total bill amount: "))45if amount < 0:6 print("Amount cannot be negative.")7elif amount < 1000:8 discount = 09elif amount < 5000:10 discount = 0.05 * amount11elif amount < 10000:12 discount = 0.10 * amount13else:14 discount = 0.15 * amount1516payable = amount - discount1718print("Discount:", discount)19print("Amount to be paid:", payable)
Output
Enter total bill amount: 6000 Discount: 600.0 Amount to be paid: 5400.0
What's going on
6000 sits in the 10% slab, so discount is 600. Put 6000 in the first branch by using the wrong comparison and you give 0%. The last else is 15% — forget it and a 20000 bill gets no extra cut.
After this program
If the idea is still fuzzy, read Day 8: Conditional Statements in the Python course. For a short check, try the Python quiz (300 questions). Stay with all 20 conditional programs, or see every topic on Python exercises.