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 trialTing-Chieh Huang
2,760 PointsShopping list with SHOW. Please Help Me. Thank you
I tried to write script by my self and I am pretty sure I did it correctly. However, the system just keeps showing error after I typed SHOW and tried to input new item into To-Do-List.
Here is my code that you can run in the workspace:
print('Please write what you like to do in the To-Do-List: ') shoplist = str(input('>')) To_Do_List = []
while shoplist != 'DONE':
if shoplist == 'SHOW':
for To_Do_List in To_Do_List:
print(To_Do_List)
shoplist = str(input('>'))
else:
To_Do_List.append(shoplist)
shoplist = str(input('>'))
print ('Here is your list: ')
for To_Do_List in To_Do_List:
print(To_Do_List)
1 Answer
Ryan S
27,276 PointsHi Ting-Chieh,
It would be helpful if you posted what error you are getting as well as format your code so we can see the indentation (see Markdown Cheatsheet).
But there are few things to note.
First, in your for loops, you shouldn't use the same variable name as the one you are iterating through. What will end up happening is that it will redefine To_Do_List as the last item you iterated through. So after the for loop is done, it will no longer be your list and instead will be a single item that is not iterable.
Instead, use a different variable name:
for item in my_list:
print(item)
Second, your for loops will not print each individual item, if that is your intention. It will just print the entire list as many times as there are items in the list, so you'd need to print(item), as shown above.
Hope this helps,
Ting-Chieh Huang
2,760 PointsTing-Chieh Huang
2,760 PointsThank you very much.!!! Your trick does solve the problem.