1

I have a program I need to write for college and I have an error in my code that I don't know how to fix

#calculate savings and print users total cost
if voucher_quant < 20:
    print("Your total will be £", str(voucher_value*voucher_quant))
    elif voucher_quant => 20 and voucher_quant=<40:
        print("Your total will be £", str((voucher_value*voucher_quant)*0.05)
        elif voucher_quant =>41 and voucher_quant =<70:
            print("Your total will be £", str((voucher_value*voucher_quant)*0.075)
            elif voucher_quant =>71 and voucher_quant =<100:
                print("Your total will be £", str((voucher_value*voucher_quant)*0.1)

can anyone help me on how to fix this?

3
  • Use if instead of elif if you are indenting them. Or else, unindent the elifs Commented Dec 10, 2021 at 5:46
  • All elif should start at the same position as if. programiz.com/python-programming/if-elif-else Commented Dec 10, 2021 at 5:46
  • Don't indent each elif statement. You also need a terminal 'else' statement Commented Dec 10, 2021 at 5:47

1 Answer 1

1

elif has to be at same identation level as its if is.

Comparison operators are like <= and not =<. = would be latter

Your print statements do not complete brackets

This code is correct syntactically

voucher_quant = 50 # Change as you want
voucher_value = 10 # Change as you want

if voucher_quant < 20:
    print("Your total will be £", str(voucher_value*voucher_quant))

elif voucher_quant >= 20 and voucher_quant<=40:
    print("Your total will be £", str((voucher_value*voucher_quant)*0.05))

elif voucher_quant >= 41 and voucher_quant <= 70:
    print("Your total will be £", str((voucher_value*voucher_quant)*0.075))

elif voucher_quant >= 71 and voucher_quant<=100:
    print("Your total will be £", str((voucher_value*voucher_quant)*0.1))


#Output
#Your total will be £ 37.5
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.