-2

I am a Python newb.

I keep getting indent errors around the if statements of my code. The first chunk of if/else statements are read fine. The second chunk results in indent errors. When I remove it for debugging. The third chunk (at the end) also returns indent errors. ...but I'm not sure where to find them?

Any suggestions on what's going wrong?

# Begin Fight/Conditions for Ending
while Player.hp > 0 and Marco.hp > 0:

    while playerchoice not in [1,2,3,4]:
        playerchoice = input("\n Which move would you like to use: ")

    marcochoice = random.choice([1,2,3,4])

    # Making the Moves - Player Always Goes First (For now!)
    if playerchoice == 1:
        Player.jabs(Marco)
        #print("\n Player - jabs - Debug")
    elif playerchoice == 2:
        ...
    else:
        #print("Player - Non-Choice - Debug")

    # Marco's Turn!
    if Marco.hp > 0:
        if marcochoice == 1:
            Marco.jabs(Player)
            #print("Marco - Jabs - Debug")
           ...
        else:
            #print("Marco - Non-Choice - Debug")
    else:
        pass

# Ending Conditional 


if Marco.hp <= 0 and Player.hp <= 0:
    print("It's a draw!")
...
else:
    print("Something has gone horribly wrong!")
jmarkmurphy
  • 11,030
  • 31
  • 59
  • Good catch, but that's my mistake in bringing it over to stackoverflow. I chopped off chunks of the code so that I didn't just leave a text-bomb. If I should plop the whole thing down though, I can (I was just yelled at on another forum for doing that, so I thought maybe not this time) – Dmitri Valentine Feb 10 '16 at 14:43
  • What about that `else:` with commented body? Did you put a `pass` there in your actual code? – tobias_k Feb 10 '16 at 14:45
  • No, I think that's related to the problem. The code wasn't running anything after the else, but by putting a pass in place of the #print(...), it acknowledged the tabbed indents afterwards. Thanks. – Dmitri Valentine Feb 10 '16 at 14:48

3 Answers3

1

It's not the quotation marks. I made that error when transferring the code to stackoverflow (modified the code for readability/compactness).

The error is with the comments by some of the else statements. Python never reads/executes anything, so it just assumes whatever follows is supposed to be indented.

Once I put pass underneath the else statements, everything cleared up.

0

It looks like your forgot the double quote

playerchoice = input("\n Which move would you like to use: ")

The color of the text could have helped you ;)

Zacaria
  • 75
  • 6
  • Good catch, but that's my mistake in bringing it over to stackoverflow. I chopped off chunks of the code so that I didn't just leave a text-bomb. If I should plop the whole thing down though, I can (I was just yelled at on another forum for doing that, so I thought maybe not this time) – Dmitri Valentine Feb 10 '16 at 14:45
0

Assuming you try to run this exact code you posted, the problem is the comment after you first 'else:' statement. The same happens here:

for i in range(10):
    if i in [0,1,2,3,4,6,7,8,9]:
        print("found")
    else:
        #print("test")
print("that could be it")

To run without problems just uncomment the second print statement. Hope that helps.

Patrick K.
  • 14
  • 3