Iainsimons
Iainsimons

Reputation: 11

I keep getting an invalid syntax but i CAN not find it

if (x == True):
     if (beverage_bought == True):
        if (fries_bought == True):
            print("You bought: " + x + " x, " + beverage + " drink, " + fries + " fries, and " + 
ketchup_string + " ketchup packets.")
            total = total - 1
        else:
            print ("You bought: " + x, " x, " + beverage + " drink, no fries and " + ketchup_string + " ketchup packets.")
        elif (fries_bought == True):
            print ("You bought: " + x + " x, nothing to drink, " + fries + " fries, and " + ketchup_string + " ketchup packets.")
        else:
            print ("You bought: " + x, " x, nothing to drink, no fries, and " + ketchup_string + " 
ketchup packets.")

print (total)

it keeps saying I have an invalid syntax for the line with elif

Upvotes: 1

Views: 65

Answers (1)

Adirio
Adirio

Reputation: 5286

You can't use elseif after else. else must be the last of the chain: if > elif > elif > else.

You should remove indents of the second elif to align it with the first if.

if x:
    if beverage_bought:
        if fries_bought:
            print("You bought: " + x + " x, " + beverage + " drink, " + fries + " fries, and " + ketchup_string + " ketchup packets.")
            total = total - 1
        else:
            print("You bought: " + x, " x, " + beverage + " drink, no fries and " + ketchup_string + " ketchup packets.")

    elif fries_bought:
        print("You bought: " + x + " x, nothing to drink, " + fries + " fries, and " + ketchup_string + " ketchup packets.")
    else:
        print("You bought: " + x, " x, nothing to drink, no fries, and " + ketchup_string + " ketchup packets.")

print(total)

Upvotes: 1

Related Questions