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 trialpavelzharnikau
3,690 PointsMy code looks completely different (shorter, works okey), but is it right?
Hi everyone! In this code workshop Kenneth offer to pause the video and try to code all by yourself. And, well, and I've done it (don't blame it, it's up to Kenneth). I've done the script, which was described in the video:
def shopping_list():
your_product_list = []
while True:
product = input("Please, add a product to your shopping list. If you want to finish, simpy type DONE: ")
if product == "DONE": break
your_product_list += [product]
print(your_product_list)
shopping_list()
First of all, it really works (God bless Treehouse!). And it's rather shot.
After this I've watched Kenneth's video and was shocked. His code looks nice and logic, but it extremely differs from my approach. So the question is: is my code okey or I miss something?
P.S. Just for information: I'm not crazy A-sicker, I just afraid that I could misunderstand some of the key concepts of Python. Will appreciate any advice.
1 Answer
Steven Parker
231,275 PointsOther than the comments, your code looks much like the video. You used the append operator (+=
) instead of the append method, but the job done is the same.
The more complex a program gets, the more ways there are to accomplish the same goal. You can expect to see this more and more as you progress.