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

Python Introducing Lists Build an Application Add Items

Angelus Miculek
Angelus Miculek
6,886 Points

i think else would've worked

while True:
    new_item = input("> ")

    if new_item == 'DONE':
        break
    elif new_item == 'HELP':
        show_help()
        continue

    add_to_list(new_item)

we have continue here so we don't add 'HELP' to our grocery list, but could an alternative option be to use else instead, like this?

while True:
    new_item = input("> ")

    if new_item == 'DONE':
        break
    elif new_item == 'HELP':
        show_help()
    else:
        add_to_list(new_item)

2 Answers

Steven Parker
Steven Parker
231,275 Points

Sure, these two bits of code do the same thing. This is quite typical, as there is rarely ever just one way to accomplish a specific task. The fact that you're thinking of effective alternative strategies is evidence of your learning progress and grasp of the material. Good job! :+1:

Steven Parker
Steven Parker
231,275 Points

Angelus Miculek — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!