Program is ignoring the last elif

Please format your code per the instructions in this post: About the Python Help category

Your final elif is missing a condition. Perhaps you meant to use else? As it is, your code will result in a SyntaxError.

Also, most of the conditions in your if clauses always evaluate to True, so none of the elif or else clauses will ever run. For example

if Type=="petrol" or "Petrol":
    total=1.40*amount

There are two problems here: First, == has higher priority than or, so this will be interpeted as (Type=="petrol") or "Petrol"

Secondly, in python, a non-empty string (like “Petrol”) is considered to be True when used in a condition. Therefore, this code is equivalent to

if (Type=="petrol") or True:
    total=1.40*amount

which will of course always run and never enter any elif or else clauses.

You should do something like this instead:

if Type in ["petrol", "Petrol"]:
    total=1.40*amount

You should also consider adding some error handling, if for example the user enters “gasoline” or something else unexpected.

2 Likes