0

Ok, so I have my program but I'm getting an "expected an indent block" and i don't know where it is I believe I have it right but I'm very confused.

##Cave fuction
def cave():

    global lvl
    global mhp
    global exp

    while True:
        print("Who whould you like to talk to. (Emily(1), James(2), Paco(3)")
        talk = int(input("Who to talk to: "))
        ptint(" ")               
        if talk == 1:
            #put storie function here
        elif talk == 2:
            #put train function here
        elif talk == 3:
            print("Your level is", lvl, "you have", mhp, "and have", exp, "EXP")
        else:
            amsterdam = 7 #filler

        print("Anthing else needed(y/n)")
        ant = input("Anthing: ")

        if ant == n:
            break
        else:
            mexico = 19 #filler
BenMorel
  • 34,448
  • 50
  • 182
  • 322

7 Answers7

2

Put pass (or print statment or anything that executes really) between your if/elif statements. The comments aren't really read as code.

Evan
  • 508
  • 1
  • 5
  • 18
2

In Python, there is no such thing as empty block like {} in C. If you want block to do nothing, you have to use pass keyword. For example:

if talk == 1:
    pass  # Put storie function here.
elif talk == 2:
    pass  # Put storie function here.

This should fix your problem. After line ending with :, next line MUST be intended, and comments do not count to indentation in that respect.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Wikiii122
  • 486
  • 3
  • 10
1

You have to put some valid statements inside if-else statements, where you have written put storie function here. Following code will not throw an error as there is some valid statement for each if-else:

def cave():

    global lvl
    global mhp
    global exp

    while True:
        print("Who whould you like to talk to. (Emily(1), James(2), Paco(3)")
        talk = int(input("Who to talk to: "))
        ptint(" ")               
        if talk == 1:
            #put storie function here
            pass
        elif talk == 2:
            #put train function here
            pass
        elif talk == 3:
            print("Your level is", lvl, "you have", mhp, "and have", exp, "EXP")
        else:
            amsterdam = 7 #filler

        print("Anthing else needed(y/n)")
        ant = input("Anthing: ")

        if ant == n:
            break
        else:
            mexico = 19 #filler
BenMorel
  • 34,448
  • 50
  • 182
  • 322
Amit
  • 19,780
  • 6
  • 46
  • 54
1

After the condition of if or elif, and after else, an indented block is expected. Something like this:

if condition:
    indented_block
elif condition:
    indented_block
else:
    indented_block

Just a comment as a block:

if condition:
    # ...

is not considered, so you have to put something there. One alternative is using a placeholder:

if condition:
    pass

pass is a null operation. When it is executed, nothing happens.

Christian Tapia
  • 33,620
  • 7
  • 56
  • 73
0

if that's the exact code you're running, your problem should be within:

while True:
    print("Who whould you like to talk to. (Emily(1), James(2), Paco(3)")
    talk = int(input("Who to talk to: "))
    ptint(" ")               
    if talk == 1:
        #put storie function here
    elif talk == 2:
        #put train function here

here you get the comment #put storie function here which is not evaluated as code so basically what python interprets is:

while True:
    print("Who whould you like to talk to. (Emily(1), James(2), Paco(3)")
    talk = int(input("Who to talk to: "))
    ptint(" ")               
    if talk == 1:
    elif talk == 2:
    […]

whereas it expects:

while True:
    print("Who whould you like to talk to. (Emily(1), James(2), Paco(3)")
    talk = int(input("Who to talk to: "))
    ptint(" ")               
    if talk == 1:
        print("python wants actual code here in an inner block")
    elif talk == 2:
        print("python wants actual code here in an inner block as well")
    […]

and thus does not compile

BenMorel
  • 34,448
  • 50
  • 182
  • 322
zmo
  • 24,463
  • 4
  • 54
  • 90
0

Your if blocks are empty. Try this

if talk == 1: pass #put storie function here elif talk == 2: pass #put train function here elif talk == 3: print("Your level is", lvl, "you have", mhp, "and have", exp, "EXP") else: amsterdam = 7 #filler

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Shovan
  • 185
  • 7
0

you need to enter some statement before the. elif talk == 2:

if talk == 1:
    print 1
elif talk == 2:
demo.b
  • 3,299
  • 2
  • 29
  • 29