Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialnoor shihab
Courses Plus Student 618 Pointsindentation error
hi when I run this code in terminal it gives indentation error referring to the (new_item) line
shopping_list = []
print("what should we pick up at the store ?")
print("Enter 'DONE' to stop adding items")
while True:
new_item = input ( "> " )
shopping_list.append(new_item)
print("here's your list:")
for item in shopping_list:
print(item)
1 Answer
Ryan S
27,276 PointsHi Noor,
It would be very helpful if you formatted your code (see Markdown Cheatsheet link). This is especially important when it comes to indentation errors since indentation is crucial in Python. If your code is actually all aligned on the left side as you have presented it, then you are getting an error because you have basically constructed a while
loop with nothing in it.
When your code is running, Python will reach the while: True:
statement and expect an indentation on the next line. When it doesn't find this, it will throw an error.
Anything that you want inside the while
loop needs to be indented.
eg.
shopping_list = []
print("what should we pick up at the store ?")
print("Enter 'DONE' to stop adding items")
while True:
new_item = input ( "> " )
shopping_list.append(new_item)
print("here's your list:")
for item in shopping_list:
print(item)
Good luck.