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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Vinod Kumar](https://secure.gravatar.com/avatar/e8002525810475feb6fd5166ad14e60c?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Vinod Kumar
944 PointsTypeError:TypeError: unsupported operand type(s) for -: 'str' and 'int'
When below code executed getting TypeError:
import os
shopping_list = []
def clear_screen():
os.system("cls" if os.name == "nt" else "clear")
def add_to_list(item):
show_list()
if len(shopping_list):
position = input("Where should i add {}?\n"
"Press ENTER to add to the list\n"
">".format(item))
else:
position = 0
try:
position = abs(int(position))
except ValueError:
psotion = None
if position is not None:
shopping_list.insert(int(position-1),item)
else:
shopping_list.append(new_item)
show_list()
def show_help():
clear_screen()
print("What should we pick up at the store?")
print("""
Enter 'DONE' to stop shoping.
Enter 'HELP' for any help.
Enter 'SHOWLIST' to review the items added to the list
""")
def show_list():
clear_screen()
print("here your list")
index = 1
for show in shopping_list:
print("{}.{}".format(index,show))
index +=1
print("-"*10)
show_help()
while True:
new_item = input("Please enter the item you want to buy ")
if new_item.upper() == "DONE" or new_item.upper() == "QUIT":
break
elif new_item.upper() == "HELP":
show_help()
continue
elif new_item.upper() == "SHOWLIST":
show_list()
continue
else:
add_to_list(new_item)
show_list()
Error:
Where should i add butter?
Press ENTER to add to the list
>
Traceback (most recent call last):
File "shoppinglist2.py", line 64, in <module>
add_to_list(new_item)
File "shoppinglist2.py", line 22, in add_to_list
shopping_list.insert(int(position-1),item)
TypeError: unsupported operand type(s) for -: 'str' and 'int'
[MOD: added ```python formatting -cf]
1 Answer
![Chris Freeman](https://uploads.teamtreehouse.com/production/profile-photos/1153532/micro_image.jpg)
Chris Freeman
Treehouse Moderator 68,425 PointsYou have a typo in your assignment of psotion
:
except ValueError:
psotion = None