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 (2015) Shopping List App Shopping List Introduction

Dolapo Sekoni
PLUS
Dolapo Sekoni
Courses Plus Student 1,431 Points

shopping list wont run

i keep getting syntax error when i tried running this scripts. kindly help check

https://w.trhou.se/jp131ecb9v.

that's the url to my workspace. file name is shopping_list.py

6 Answers

Hello!

The new_item input looks good, but below that nothing else is in the while block, you need to be indented inside your while loop to run, then any thing below a "IF" also needs to be indented. Make sure you have a colon at the end of a "IF" :) if i can help more just ask

Dolapo Sekoni
PLUS
Dolapo Sekoni
Courses Plus Student 1,431 Points

thanks Jason,

i am totally new to programing, i have a colon at the end of the see it below. it isn't printing the list. am really confused. please help.

while True: # ask for new items new_item = input("> ")

be able to quit the app

if new_item == 'DONE': 
    break

Hello, I'm on my phone right now, when i get back to my computer tomorrow I will walk you through it :)

I have added my new answer, check it out and let me know if you need more help!

hello again!

So here is what i got for you

# make a list to hold onto our items
shopping_list = []

# print out instructions on how to use the app
print(" What should we pick up at the store?")
print("Enter 'DONE' to stop adding items.")

while True:
# ask for new items
    new_item = input("> ")
# be able to quit the app
    if new_item == 'DONE': 
        break   
# add new items to our list
    shopping_list.append(new_item)
# print out the list
    print("Here's your list:")

    for item in shopping_list:
          print(item)

That is how you want your code to look, on yours, your # are all on different lines, move them up so there is no space between lines like you see how mine is. You also need the New_item = input to be pushed/indented in 1 more space, on your code, go to the IF new-item and backspace it to line up with the # with ask for new items, then indent it 4 times, so press the space bar 4 times your IF new_item .. that was out of the while loop, you want it be indented under the while loop for it be triggered in that loop, the same with everything below new_item you want to indent all of those under the while loop and to line up with the If new_item, like you see on mine. You want them indented to the same area, but anything you want to be inside that IF block needs be indented PAST that IF block, like where "break" is on the IF new_item that is in that IF block, but shopping_list.append that is out of the IF block, but it is in your while loop, so it will continue to trigger until told to stop, which is what you want for this specific code. As well at the bottom your Print(item) was not indented correctly and needed to be pushed/indented in 2 more spaces. Lastly you had shopping_list.append(new_list) which new-list was never defined so it cannot be used, you want to do shopping_list.append(new_item) because new item is what is being inputted by the user and will be retained into the shopping_list.

Any further questions feel free to ask!

It seems frustrating and very scary at the beginning i know, but keep pushing through and don't give up, you will get it i promise! Every new programmer makes thousands of mistakes, you're totally not alone here!

Dolapo Sekoni
PLUS
Dolapo Sekoni
Courses Plus Student 1,431 Points

thanks so much for your time. i did it back to back like you did and while the there was no error message it prints "here's your list" after every item i put in then when i type 'DONE' i just get the item with no "here's your list.

kindly help check

https://w.trhou.se/b6214zx8nl

thanks dolapo

Dolapo Sekoni
PLUS
Dolapo Sekoni
Courses Plus Student 1,431 Points

also kindly help check my number_game.py also. it brings the first prompt to input number but after i do that i get the error message "guess isn't defined"

https://w.trhou.se/53ttnoyyik

thank you

Sorry for the late response! When i get back to my PC I'll gladly check it all out!

for the shopping list you want to switch the print(heres you list) to the IF == done block, you want to put it right above break, so if you enter done it will print heres your list and then will break the while loop.

For the number game, You have secret number as your random generated number, but also using secret number to ask for input from the user, you want to do this instead ''' guess = int(input("guess a number between 1 and 10: ")) ''' because using the secret number as the random generated number and the user guess makes it negate itself kinda, you cant have the random number be the secret number variable and have the user input be the secret number variable, the input needs to be a different variable.

hope that helps!