#๐Ÿ”’ Why does my thing keep showing invalid syntax?

20 messages ยท Page 1 of 1 (latest)

vernal heraldBOT
#

@silent flame

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.

neon flume
#

!code

vernal heraldBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

silent flame
#

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

pliant galleon
#

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")
pliant galleon
silent flame
#

So what should I try

pliant galleon
#

Try giving one tab space for all statements inside your if block:

if <some condition>:
  <statement 1>
  <statement 2>
  etc...
silent flame
#

ok

#

thanks

pliant galleon
#

np ๐ŸŽ‰

neon flume
#

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.

silent flame
#

ok

#

It worked so thanks everyone

vernal heraldBOT
#
Python help channel closed

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.