#๐Ÿ”’ Something wrong with some invalid syntax

48 messages ยท Page 1 of 1 (latest)

austere apexBOT
#

@urban mason

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

urban mason
#

Help me fix it as its due in 2days

quiet forge
#

You cannot have an elif after an else

#

It goes if -> any number of elifs -> else

#

It looks like in this case you meant the extra addons elif to be part of the extra addons if, but it's indentented too far for that

urban mason
#

So how am I going to write this code properly like fix that bit I've been working on this I am stresssed

quiet forge
#
if one: # <--  first if
  if two: # <--  indented second if
    ...
  elif two: # <-- indented the same as the second if so belongs to the seoond if
    ...
  else: # <-- indented the same as the second if so belongs to the second if
else: # <-- indented the same as the first if so belongs to the first if
  ...```
urban mason
#

I am lost

quiet forge
#

The problems start at elif extra_addons

urban mason
quiet forge
#

That elif is supposed to be part of if extra_addons == "yes": but because it's indented wrong it gives an error

urban mason
quiet forge
#

Yes, it should be dedented to match the if

urban mason
#

Like that?

quiet forge
#
if:
  code
  if:
    code
  elif:
    code
  else:
    code
elif:
  code```
urban mason
#

does it need the ":" tho

#

or at the end

quiet forge
#

Yes

urban mason
#

the way Ive done this one is it fine?

quiet forge
#

Yes

urban mason
#

do I move everything here a bit more left or

#

like below the if

quiet forge
#

In python we generally use an indentation of 4 spaces per level

#

In most editors a single tab will be replaced by 4 spaces

urban mason
#

So like that

quiet forge
#

That portion is looking goood

urban mason
urban mason
#

order_addons = True
print ("This is the list of available extra addons")
for addons in available_add_ons:
print(addons)
print()
while order_addons:
extra_addons = input("Would you like an extra add on? yes or no?")
if extra_addons == "yes":
addons = input("Which one would you like to add")
if addons in available_add_ons:
final_order.setdefault(pizzas, [])
final_order[pizzas].append(addons)
print(f"I have added {addons}.")
sub_total.append(addon_prices[addons])
else:
print(f"I am sorry, we don't have {addons} available.")

elif extra_addons =="no":
        break
    for key, value in final_order.items():
        print(f"/nYou have order a {key} trim with {value}")
    check_order = True
    while check_order:
        print()
        order_correct = input("Is this correct? yes/no ")
        if order_correct == "yes":
            check_order = False
            order_pizzas = False
        if order_correct == "no":
            print(final_order)
            add_remove = input("would you like to add or remove?")
            if add_remove == "remove":
                remove = input ("Which pizza would you like to remove? ")
                del final_order[remove]
                print(final_order)
            if add_remove == "add":
                check_order = False
urban mason
#

So is that fine @quiet forge

glossy hearth
#

there is a type

#

it should be append not apend

#

the second line after the if statement

urban mason
glossy hearth
#

yes

#

use visual studio code for intellisense

#

it will help reduce such issues

urban mason
#

Where

#

Theres still

#

syntax error

glossy hearth
#

move the if and else statement under the if extra_addons == "yes" below the line addons = ...

#

and don't just install vs code open your file and then revise it

austere apexBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.