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 trial
John DiGiovanni
Courses Plus Student 902 PointsWays to do the Shopping List.
Hi,
So I reached the point in treehouse where I had to solve the shopping lists problem. I came up with a different way to meet the criteria needed to make the program work. I was wondering how much worse mine was in comparison to how the instructor solved it. Any Feedback is appreciated.
print("Let's make a grocery list! Enter items below and then type 'DONE' when finished!")
print("Type 'SHOW' to show you the list so far and type 'HELP' to remind you what the other functions do.")
my_list = []
item = input()
def grocery(item):
while item != 'DONE':
if item == 'SHOW':
print("Here’s Your List So Far:")
print(", ".join(my_list))
elif item == 'HELP':
print("***HELP***")
print("SHOW - SHOWs the current list so far")
print("DONE - COMPLETEs the list and prints the final version")
print("***HELP***")
my_list.append(item)
for item in my_list:
if item == 'SHOW':
my_list.remove('SHOW')
elif item == 'HELP':
my_list.remove('HELP')
item = input()
print("Here’s your list:")
print(", ".join(my_list))
grocery(item)
Jeff Muday
Treehouse Moderator 28,732 PointsJeff Muday
Treehouse Moderator 28,732 PointsIt is good to recognize that there are infinite ways to write programs. And it is wise to solicit advice about other ways to do things. Whether or not I am qualified to give advice is another question entirely!
Here would be my suggestions:
0 - always have fun, always be learning!
1 - more comments. Always more comments will help your reader out, and may even help you see a design pattern that is emerging. And when you get old like me, the comments will help you remember what you were thinking about the code.
2 - I would try to have only ONE place where you take input from the user. This will allow you to troubleshoot it easier and someday when you need to prepare a program for internationalization there are fewer places to translate prompts. I'd put the input at the "top" of the loop, but you are using a Sentinel strategy for loop termination, you'd have to set the item before you came into the loop.
3 - It is extra work when you have to remove the meta commands 'SHOW' and 'HELP' from your list. You might want to look into using a "continue" statement at the end of those if blocks. But no one will accuse you of not knowing the "remove" command on a list!!
4 - it would be nice to return the list you built at the end of the loop.