Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Shopping List App Shopping List Introduction

pavelzharnikau
pavelzharnikau
3,690 Points

My 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
Steven Parker
215,958 Points

Other 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.