Reputation: 191
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
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
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