Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A21 inventory #30

Open
darkseid-03 opened this issue May 31, 2023 · 0 comments
Open

A21 inventory #30

darkseid-03 opened this issue May 31, 2023 · 0 comments

Comments

@darkseid-03
Copy link

def create_inventory(items):
inventory_dict={}
for i in items:
if i not in inventory_dict:
inventory_dict[i]=1
elif i in inventory_dict:
inventory_dict[i]+=1
return inventory_dict

def add_items(inventory_dict,items):
for j in items:
if j in inventory_dict:
inventory_dict[j]+=1
if j not in inventory_dict:
inventory_dict[j]=1
return inventory_dict

def decrement_items(inventory_dict,items):
for j in items:
inventory_dict[j]-=1
if inventory_dict[j]<0:
inventory_dict[j]=0
return inventory_dict

def remove_item(inventory_dict,item):
item_List=list(inventory_dict.keys())
for i in item_List:
if i==item:
inventory_dict.pop(i,None)
return inventory_dict

def list_inventory(inventory_dict):
inventory_list=[]
for key in inventory_dict:
inventory_tuple=()
if inventory_dict[key]>0:
inventory_list.append((key,)+(inventory_dict[key],))
return inventory_list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant