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 Python Basics (Retired) Shopping List Shopping List Project

Jason Nelson
Jason Nelson
6,209 Points

Python Shopping list

in the shopping list section of python basics I'm having trouble understanding a part of the syntax.

while True: new_item = input("> ")

I'm not sure what the ("> ") is for in the syntax. Is it a way to prevent you from adding nothing to the list?

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

The "> " is simply for a visual prompt. You could have used input("Enter here: ")

Not including a prompt with input() will stop the program waiting for the user to enter something. However without the prompt, the user may think the program has frozen.

The way to prevent adding "nothing" to the list is to check the return value:

while True:
    new_item = input("> ")
    if not new_item:
        # take action if no input
        print("No input entered") #<-- give feedback, perhaps add menu help
        continue #<-- loop back to beginning to get new input. 
Jason Nelson
Jason Nelson
6,209 Points

Ahh this makes since, I prefer the "Enter here" syntax, it's much more clear.