#๐ Why does my thing keep showing invalid syntax?
20 messages ยท Page 1 of 1 (latest)
@silent flame
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.
!code
Is my code not included?
adventure3c = input("You find the source of smoke and find a tribe of cannibals! Do you approach them or hide to the left? (approach/hide): ")
if adventure3c.lower() == "approach":
print("You approached the tribe of cannibals. The cannibals captured and killed you. You failed to find the Alchemist and failed to cure your dog.")
print()
ending = "ENDING 1, Failed once, get up again"
print(ending)
exit()
elif adventure3c.lower() == "hide":
print("You hide to the left.")
adventure4c = input("You see a small hut in the distance from your hiding spot. But then you spot a rusted steel blade on the ground. Do you go to the hut or attack the cannibals? (hut/attack): ")
if adventure4c.lower() == "attack":
Error code:
File "<exec>", line 114
elif adventure3c.lower() == "hide":
^^^^
SyntaxError: invalid syntax
What the user meant above was to put your code inside backticks (`) so that your message looks like this and is easier to read
print("Hi")
And I think your problem is that you have not given the proper indentation for the statements in the if block
So what should I try
Try giving one tab space for all statements inside your if block:
if <some condition>:
<statement 1>
<statement 2>
etc...
np ๐
Because print() isn't indented, that basically says "the previous if has ended". That means that when the elif is reached, there is no if for it to match to, which is illegal.
So ya, like they mentioned, you need to indent the lines so they're inside the if.
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, 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.