Advertisement
Guest User

08. Feed the Animals

a guest
Feb 18th, 2020
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. full_list={}
  2. while True:
  3.     command=input()
  4.     if command=="Last Info":
  5.         break
  6.     command=command.split(":")
  7.     command[2]=int(command[2])
  8.     if command[0]=="Add":
  9.         if command[1] not in full_list.keys():
  10.             full_list[command[1]]=command[1:]
  11.         else:
  12.             full_list[command[1]][1]+=command[2]
  13.     if command[0] == "Feed" :
  14.             try:
  15.                 full_list[command[1]][1]-=command[2]
  16.             except :
  17.                 continue
  18.     if full_list[command[1]][1]<=0:
  19.         print (f"{command[1]} was successfully fed")
  20.         full_list.pop(command[1])
  21. #Animals:
  22. lst=[]
  23. for k,v in full_list.items():
  24.     lst.append(v[:2])
  25. n=sorted(lst, key=lambda x: (-x[1], x[0]))
  26. print ("Animals:")
  27. for _ in n:
  28.     print (f"{_[0]} -> {_[1]}g")
  29. #Areas with hungry animals:
  30. print ("Areas with hungry animals:")
  31. areas={}
  32. for k,v in full_list.items():
  33.     if v[2] not in areas:
  34.         areas[v[2]]=1
  35.     else:
  36.         areas[v[2]]+=1
  37. for k,v in areas.items():
  38.     print (f"{k} : {v}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement