sarahHH
sarahHH

Reputation: 191

expected an indented block python error

I am new to Python so don't know much about it. But I know the basics of indentation and I cannot solve the error of expected an indented block in the following code.

meal =["egg","milk","spam","tomato"]

for item in meal:
    if item =="spam":
        nasty_food =item
        break

if nasty_food:
   print("there is nasty food")

Upvotes: 1

Views: 97

Answers (2)

Chuk Ultima
Chuk Ultima

Reputation: 1037

Visually I don't see an indentation issue in the code you posted. Verify that you are not mixing up tabs and spaces as that can also lead to indentation issues.

Upvotes: 0

Ilija
Ilija

Reputation: 1604

You have to indent code with consistency since that is a must do in Python.

Don't use different number of spaces for indent per function. This will lead you to new issues.

Try this code:

meal = ["egg", "milk", "spam", "tomato"]

for item in meal:
    if item == "spam":
        nasty_food = item
        break

if nasty_food:
    print("there is nasty food")

Upvotes: 1

Related Questions