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 Collections (Retired) Lists Redux Shopping List Take Three

Shrinivas Ganesan
PLUS
Shrinivas Ganesan
Courses Plus Student 5,923 Points

Issues with the assignment operator +=

count += 1

This generates an "invalid syntax" error in workspace. I tried it independently in the console and it worked fine. Suggestions please?

Stone Preston
Stone Preston
42,016 Points

can you post the full code you tried

Stone Preston
Stone Preston
42,016 Points

hmm the code you posted seems to have disappeared.

1 Answer

Stone Preston
Stone Preston
42,016 Points

there was nothing wrong with your count code, you did have a lot of incorrect indentation. I fixed the indenting problems and now it compiles fine without any errors. The edited code is below:

shopping_list = []
def show_help():
  print("\n Separate each item with a comma")
  print("\n Enter DONE to quit, enter SHOW to check your current list " "and enter HELP to see this message")

def show_list():
    count = 1
    for i in shopping_list:
        print("{}: {}".format(count,i))
        count +=  1

show_help()

while True:
          new_stuff = input(">")
          if new_stuff == "DONE":
            show_list()
            break

          elif new_stuff == "HELP":
            show_help()
            continue

          elif new_stuff == "SHOW":
            show_list()
            print("\n You currently have {} items in your list".format(len(shopping_list)))
            continue

          else:
            new_list = new_stuff.split(',')
            index = input("Where do you want to place this item? Press enter for end of list " "or return a number")
            if index: 
              try:
                ind = int(index)
                spot = ind - 1
                for item in new_list:
                  shopping_list.insert(spot,item.strip())
                  spot += 1
              except:
                ind = float(index)
                print("\n Please enter a whole number!")
                show_help()
            else:
              for item in new_list:
                shopping_list.append(item.strip())
Stone Preston
Stone Preston
42,016 Points

just be sure you indent your code blocks consistently.