[Solved] Need help, got stuck with the python code [closed]


Something like this, where repetitive code is avoided and some error handling for user input:

(Plus, you math was a little off, since 50,000, 100,000, and 200,000 are not being handled at all, example: (cost) < 50000 and (cost) > 50001 leaves 50,000 as a gap, since it is neither less than 50,000 or greater than 50,001.

while True:
    try:
        cost = int(input("What is the cost of your house?"))
        tax = None

        if cost <= 50000:
            tax = 0
        elif 50000 < cost <= 100000:
            tax = 1
        elif 100000 < cost <= 200000:
            tax = 1.5
        elif cost > 200000:
            tax = 2

        if tax == 0:
            print("You don't have to pay tax")
        else:
            print("You have to pay {}% tax of ${:.2f}".format(tax, (cost/100)*tax))
        break
    except Exception as e:
        print("Bad value entered,", e)

solved Need help, got stuck with the python code [closed]