-1

I do not understand why the syntax error is there as this same syntax was used previously. The syntax error is:

  File "main.py", line 11
    else size == L or l:
         ^^^^
SyntaxError: expected ':'
print("Welcome to Python Pizza Deliveries!")
size = input("What size pizza do you want? S, M, or L ")
add_pepperoni = input("Do you want pepperoni? Y or N ")
extra_cheese = input("Do you want extra cheese? Y or N ")

pizza = int(0)
if size == S or s:
    pizza += 15
elif size == M or m:
    pizza += 20
else size == L or l:
    pizza += 25

if add_pepperoni == Y or y:
    if size == S or s:
        pizza += 2
    else size == M or m or L or l:
        pizza += 3

if extra_cheese == Y or y:
    pizza += 1

print(f"Your final bill is: ${pizza}.")


#File "main.py", line 11
#    else size == L or l:
     ^
#SyntaxError: invalid syntax
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Alex
  • 1
  • 2
  • 3
    That absolutely doesn't do what you think it does, even if `S` etc. have been defined somewhere: https://stackoverflow.com/questions/20002503/why-does-a-x-or-y-or-z-always-evaluate-to-true. But `else` doesn't have any condition, it's either `elif :` or just `else:`, you've definitely never used `else :` in any working Python code. – jonrsharpe Nov 19 '21 at 16:07
  • In slightly different words, `else:` is - always - the kitchen sink for everything which didn't match any condition. If that's not what you mean, you probably want `elif`. – tripleee Nov 19 '21 at 16:15

2 Answers2

0

You need to replace the S or s with:

if size == 'S' or size == 's':
    #do something
elif size == 'M' or size == 'm':
    #do something
...

Or, you could even just lowercase the input strings and do:

if size == 's':
    #do something
elif size == 'm':
    #something else
...

First of all, S is not a variable, it needs to be a string, and secondly, the or s part won't work. The or s part is converting the variable s to a boolean value. What you need to do is compare size with 's' and 'S'.

2pichar
  • 1,348
  • 4
  • 17
0

Thank you to those who helped. I figured out what was wrong and will put it here in simple terms to hopefully help someone else. Two things to remember.

  1. When doing the size = s you need to put it in quotes since it came in as a string.

  2. You can either do an "elif {condition}:" or an "else:" not an "else {condtion}:"

Alex
  • 1
  • 2