Need help with running the code, i can run the block individually but altogether i get errors when i execute says syntax error after using elif followed by if

age=int(input(“entre age:\n”))
if age<8:
print(“you can avail 10% discount”)
prescription=input(“enter prescription no. :\n”)
bill=float(input(“entre amt”))
print(“discounted amt is:\n”,discount_amt)
print(“amt to be paid is:\n”,total)
elif age>60:
print(“you can avail 20% discount”)
prescription=input(“enter prescription no. :\n”)
bill=float(input(“enter amt”))
print(“discounted amt is:\n”,discount_amt)
print(“amt to be paid is:\n”,total)
else if age in range(8,60):
print(“no discount for your age”)

I’ve edited the original post, but it looks like the formatting wasn’t there to begin with as it’s still a solid block of Python…

@beta9649826136, you can learn how to format your code by reading this topic.


else if is not a valid construct in Python.

You start a conditional branch with if, elif is the portmanteau of “else if” which declares another condition, and else is the final catch-all if no previous conditions match:

if condition1:
    do something
elif condition2:
    do something else
elif condition3:
    do another thing
    nothing matches, do this

Whether there are any other issues remains to be seen, as we have no idea how you indented the program…


Indentation matters in Python. This might be helpful too:

1 Like