Python Forum

Full Version: I need help with my game, help please?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Ok, so I needed help with my game. Huh Huh Huh Huh
Here is the info. I'm running windows 8.1 pro and my python version is 3.7.5. I also use an IDE, I'm using Pycharm. Here is the code:
#start point
name = input("hello, welcome to a game. what is your name")
print ("ok, " + name + "lets go!")
ophp = 20
uhp = 50
#the main game code
while ophp or uhp > 0:
    thechoice = input("You meet ummmmm, a skeleton? 1 for Sword of Light, 2 for Empty Gun (from undertale), 3 The Really Good Steak")
    if thechoice: 1
    ophp = -5
    uhp = -2
    print("you caused " + ophp + "damage and you took " + uhp + "damage.")
    print("\a")
    elif thechoice: 2
    ophp = -10
    uhp = -2
    print("you caused " + ophp + "damage and you took " + uhp + "damage.")
    elif thechoice 3:
    print("\a")
    uhp = +5
    print("you restored 5 hp!")
else:
 print ("what?")
if uhp >1:
    print("\a")
    print("you lost.")
    input("/n/nPress the enter key to exit, and well you got the bad ending, so yeah.")
else:
    print("\a")
    print("You win!")
    input("/n/nPress the enter key to exit.")
and here's the error.
Error:
C:\Users\Etan\PycharmProjects\yayisgreathowmanyyaydoyouyay\venv\Scripts\python.exe C:/Users/Etan/.PyCharmCE2019.2/config/scratches/scratch.py File "C:/Users/Etan/.PyCharmCE2019.2/config/scratches/scratch.py", line 14 elif thechoice: 2 ^ SyntaxError: invalid syntax Process finished with exit code 1
Do you have any idea to fix this error? And also fix any other bugs? Please no bullying or trolling! I just needed help!
You can't have an elif on it's own like that. Also, the condition for the if and the elif are the same. Here's how if/elif works:

if spam == 1:
    do_something()
    do_something('silly')
elif spam == 2:
    spanish_inquisition()
else:
    stop_it()
Lines 2 and 3 only execute if the value of spam is 1. Line 5 only executes if the value of spam is 2. The last line executes if spam is neither 1 nor 2. All of this only works because of the indentation. The indentation indicates which code is executed by each of the statement. In between the if and the elif, everything must be indented, or you will get a syntax error.