Karnataka KSEAB II PUC Information Technology (Vocational) study materials
Karnataka KSEAB II PUC Information Technology (Vocational) study resources

Bus Pass Fee Calculator That Overcharges a Girl Student

Karnataka KSEAB II PUC Information Technology (Vocational) · Put your knowledge to work in context.

All case studies

Bus Pass Fee Calculator That Overcharges a Girl Student

A vocational IT student writes a Python program for the school bus pass counter. The fee slabs are: distance up to 5 km ₹600; more than 5 and up to 10 km ₹900; more than 10 and up to 15 km ₹1200; more than 15 km ₹1500. Girl students get a 20% concession on the slab fee. A late fee of ₹100 is added if payment is after the due date. The student’s code is:

fee = 0
if dist <= 5:
    fee = 600
elif dist <= 10:
    fee = 900
elif dist <= 15:
    fee = 1200
else:
    fee = 1500
if gender == 'F':
    fee = fee - 20
if late == 'Y':
    fee = fee + 100
print(fee)

For a girl student travelling 12 km and paying late, the program prints ₹1280. For a boy travelling 18 km and paying on time, it prints ₹1500. The teacher says the girl’s output is wrong, and also wants the program to reject distances of 0 or less and distances above 40 km.

1. Trace the girl student’s fee at 12 km with late payment, identify the logic error, and state the correct output.

Read the worked answer

At 12 km the elif dist <= 15 branch sets fee = ₹1200. The code then does fee = fee - 20, which subtracts ₹20, giving ₹1180; adding ₹100 late fee gives ₹1280. That matches the printed value but is wrong because the concession is 20% of the slab fee, not ₹20. Correct concession = 0.20 × 1200 = ₹240, so fee after concession = ₹960; late fee = ₹1060.

The error is a units/percentage mistake: 20 was used instead of fee * 0.20 (or fee * 20 / 100). A second, smaller issue is that currency should be rounded to the nearest rupee if percentages produce paise. The boy’s ₹1500 at 18 km is correct because no concession or late fee applies.

2. Add validation for distance (reject ≤0 or >40 km) and rewrite the fee logic clearly. Give boundary test cases.

Read the worked answer

Use a loop to reject invalid input, then apply slabs in ascending order.

if dist <= 0 or dist > 40:
    print('Invalid distance')
else:
    if dist <= 5: fee = 600
    elif dist <= 10: fee = 900
    elif dist <= 15: fee = 1200
    else: fee = 1500
    if gender == 'F':
        fee = fee * 0.80
    if late == 'Y':
        fee = fee + 100
    print(round(fee))

Boundary tests should include 0 (reject), 1 (600), 5 (600), 5.1 (900), 10 (900), 10.1 (1200), 15 (1200), 15.1 (1500), 40 (1500), 40.1 (reject). Also test a girl at 5 km late: 600 × 0.8 + 100 = 580, and a boy at 10 km on time = 900. Boundary tests catch <= vs < mistakes.

3. Why does the order of `elif` conditions matter? What would happen if the first condition were `dist <= 15`?

Read the worked answer

elif is evaluated top to bottom, and the first true condition wins. The slabs are cumulative ranges, so they must be tested from smallest to largest. If the first condition were dist <= 15, then every distance from 0 to 15-including 3 km and 8 km-would be charged ₹1200, and the ₹600 and ₹900 slabs would never run. Distances above 15 would still fall to else and get ₹1500. The program would not crash, so the error would be a silent overcharge.

A good test set with 3 km, 8 km, 12 km and 18 km exposes it immediately. The same ordering rule applies to grade formulas and tax slabs.