Home > Blockchain >  Python: Error occurring in IF/ELIF statement
Python: Error occurring in IF/ELIF statement

Time:12-13

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?

CodePudding user response:

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
  • Related