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 (2016, retired 2019) Lists Shopping List Take Three

vikas Rai
vikas Rai
9,703 Points

When i am pressing ENTER or characters to put the item the in the end then i am getting error.

Here is your list:

  1. coke
    at which position you want to put this item?
    press ENTER if you want to put this item at the end
    > fdhfhf
    Traceback (most recent call last):
    File "l.py", line 66, in <module>
    add_to_list(new_item)
    File "l.py", line 34, in add_to_list
    whole_list.insert(position-1,item)
    TypeError: unsupported operand type(s) for -: 'str' and 'int'

1 Answer

vikas Rai
vikas Rai
9,703 Points

Sorry guys, there was an typing error in my code:

else: position=0 try: position=abs(int(position)) except ValueError: ** postion = None if position is not None: whole_list.insert(position-1,item) else: whole_list.append(item) display_order()