#๐ Something wrong with some invalid syntax
48 messages ยท Page 1 of 1 (latest)
@urban mason
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.
Help me fix it as its due in 2days
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
So how am I going to write this code properly like fix that bit I've been working on this I am stresssed
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
...```
so did I do the first if one correct and the second but need to change the
- if extra_addons == "yes":
2.if addons in available_add_ons:
so do I change that?
I am lost
The problems start at elif extra_addons
so do I change it to if?
That elif is supposed to be part of if extra_addons == "yes": but because it's indented wrong it gives an error
So should Indent the line properly?
Yes, it should be dedented to match the if
Like that?
if:
code
if:
code
elif:
code
else:
code
elif:
code```
Yes
the way Ive done this one is it fine?
Yes
In python we generally use an indentation of 4 spaces per level
In most editors a single tab will be replaced by 4 spaces
That portion is looking goood
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
So is that fine @quiet forge
there is a type
it should be append not apend
the second line after the if statement
Apart from that is the code fine
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
I am a bit lost
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.