Road tax by car price

EasyIf-Else Programs · 57 of 64

Write a Python program to display road tax: price below 5,00,000 pays 15,000; below 10,00,000 pays 50,000; below 15,00,000 pays 80,000.

Advertisement
Input
1200000
Output
450000 -> tax: 15000
1200000 -> tax: 80000
1800000 -> tax: not covered by these slabs

Approach

  1. Test the price bands from the lowest upwards.

Solution

Python
def road_tax(price):    if price < 500000:        return 15000    elif price < 1000000:        return 50000    elif price < 1500000:        return 80000    else:        return "not covered by these slabs" for price in [450000, 1200000, 1800000]:    print(price, "-> tax:", road_tax(price))
Output
450000 -> tax: 15000
1200000 -> tax: 80000
1800000 -> tax: not covered by these slabs

Line by line

Lines 2-7

Each elif only runs when the price is above the previous band.

Note

The original sample said a 12,00,000 car pays 50,000, but by the given rules prices from 10,00,000 to 15,00,000 pay 80,000.

Learn the concept

New to this topic? Read the lesson, then come back.

More if-else programs

← All 64 If-Else Programs

Leave a Comment