Founding Batch Offer · HLD · LLD · System Design at ₹799 until 30 Nov

Bill Discount System in Python

Take one discount percentage off a Python bill. A beginner threshold exercise contrasts this policy with slabs and keeps negative amounts out of payment math.

BeginnerConditional ProgramsExample 17 of 20
bill-discount-system.py
1# Program for bill discount system
2
3amount = float(input("Enter total bill amount: "))
4
5if amount < 0:
6 print("Amount cannot be negative.")
7elif amount < 1000:
8 discount = 0
9elif amount < 5000:
10 discount = 0.05 * amount
11elif amount < 10000:
12 discount = 0.10 * amount
13else:
14 discount = 0.15 * amount
15
16if amount >= 0:
17 payable = amount - discount
18 print("Discount:", discount)
19 print("Amount to be paid:", payable)

Output

Amount to be paid: 5400.0

10% of 6000.0 is 600.0, leaving 5400.0 to pay.

In this one

  • Choose one whole-bill percentage
  • Subtract a discount from the original total
  • Avoid using an unassigned branch variable

How it works

  1. 1

    Read amount and choose the matching discount branch.

  2. 2

    For valid amounts only, compute payable = amount - discount.

  3. 3

    Print the discount and remaining amount inside that valid branch.

Edge cases

Exact 5000

Enter 5000.

The < 5000 test fails, so the 10% band applies.

Negative bill

Enter -10.

Only the error message prints; payment calculations are skipped.

What's going on

A 6000 bill reaches the 10% band, so the discount is 600 and the payable amount is 5400. This is one percentage on the whole bill, not a progressive charge on separate pieces.

The ladder checks increasing upper limits: below 1000 gives none, below 5000 gives 5%, below 10000 gives 10%, and the final else gives 15%. Exact boundary values enter the next band because the comparisons use <.

Negative amounts print an error. The separate amount >= 0 guard ensures the final subtraction only runs after discount was assigned. Without it, the negative branch would reach an undefined discount name. Real billing also needs money rounding rules; float arithmetic here is for learning the conditional policy.

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.

Quiz

Tap an option. The answer stays hidden until you pick.

Question 1

Is the 10% applied only to the part above 5000?

Pick an answer to check it.

Question 2

Why guard the final subtraction?

Pick an answer to check it.

Questions people ask

Is the 10% applied only to the part above 5000?

No. This policy applies the selected percentage to the entire bill.

Why guard the final subtraction?

Negative input does not assign discount, so the calculation must not run for that branch.

What discount does exactly 1000 receive?

It receives 5%, because it is not below 1000 but is below 5000.