Why is this outputting '3/4 Tank' with the following input?

Viewed 26
def gas_price(previous, new):
    percent = (new / previous) - 1
    if new == previous:
        decision = 'Full Tank'
    elif percent < .2:
        decision = '3/4 Tank'
    elif .20 <= percent < .80:
        decision = 'Half Tank'
    elif .80 <= percent < 1.00:
        decision = '1/4 Tank'
    else:
        decision = 'Go Home'
    return decision

So here is the function I've created, when I use the input gas_price(100.0, 120.0) the return should be 'Half Tank' because the price has increased by 20% or more. Why is '3/4 Tank' returning when percent = .2?

0 Answers
Related