Python Forum
Syntax Error (elif statement)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Syntax Error (elif statement)
#1
I’m following a tutorial on youtube on how to code a very simple game.
The part of my code which recieves the error looks like this:
player_choice = input()

if player_choice == '1':
    monster['health'] = monster['health'] - player['attack']
    player['health'] = player['health'] - monster['attack']

edit 2: Nvm I solved i, forgot parantheses at player health
    print(monster['health'])
    print(player['health']
elif player_choice == '2':
    print(Heal Player)
else:
    print(Invalid Input)
The error I recieve:
    elif player_choice == '2':
    ^
SyntaxError: invalid syntax
I’ve compared my codes with the tutorial and it is almost exactly identical
Heres the video for reference: https://youtu.be/kDdTgxv2Vv0?t=1843

edit: This is what's stated in the "problems" tab in VS code (line 15 in VS code being Line 8 in here, since I cut some of the code out ofc):
"message": "invalid syntax (<unknown>, line 15)"
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Syntax error for "root = Tk()" dlwaddel 15 1,160 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 374 Jan-19-2024, 01:20 PM
Last Post: rob101
  An unexplainable error in .format statement - but only in a larger piece of code? ToniE 4 696 Sep-05-2023, 12:50 PM
Last Post: ToniE
  Syntax error while executing the Python code in Linux DivAsh 8 1,545 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 1,206 Jun-19-2023, 03:35 AM
Last Post: 007sonic
Question If, elif, and else statement not working PickleScripts 3 884 Mar-30-2023, 02:53 PM
Last Post: PickleScripts
  syntax error question - string mgallotti 5 1,297 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  Syntax error? I don't see it KenHorse 4 1,243 Jan-15-2023, 07:49 PM
Last Post: Gribouillis
  Syntax error tibbj001 2 882 Dec-05-2022, 06:38 PM
Last Post: deanhystad
  Python-for-Android:p4a: syntax error in main.py while compiling apk jttolleson 2 1,829 Sep-17-2022, 04:09 AM
Last Post: jttolleson

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020