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")) discount_amt=(bill/100)*10 print("discounted amt is:\n",discount_amt) total=bill-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")) discount_amt=(bil/100)*20 print("discounted amt is:\n",discount_amt) total=bil-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 your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (
</>) to add backticks around text.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).
you need to write
else: <stuff inside else>
with proper indentation and everything
if you want an if inside the else the block inside the if needs to be even more indented
why don’t you just use a second
elif? or just an
Okay so first your range is wrong. Remember the second parameter is not included so if you want to get age 60 in there you need to change your range to this: range(8, 61)
For me it would be way easier to do it this way:
if age < 0:
print(“Enter a valid age”)
elif age < 8:
elif (age > 8) and (age < 60 ):
I hope that helps!