Advertisement
aneliabogeva

Travel company

Jul 8th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. cities = {}
  2.  
  3. while True:
  4. command = input()
  5. if command == "ready":
  6. break
  7. a = [item for item in command.split(":")]
  8. city = a[0]
  9.  
  10. b = [item for item in a[1].split(",")]
  11.  
  12. for i in b:
  13. c = [item for item in i.split("-")]
  14. if city not in cities:
  15. cities[city] = {}
  16. cities[city][c[0]] = int(c[1])
  17. for city, transport in cities.items():
  18. cities[city] = sum(transport.values())
  19.  
  20. while True:
  21. command = input()
  22. if command == "travel time!":
  23. break
  24. a = [item for item in command.split(" ")]
  25. check_city = a[0]
  26. value = int(a[1])
  27. if check_city in cities:
  28. if value <= cities[check_city]:
  29. print(f"{check_city} -> all {value} accommodated")
  30. else:
  31. print(f"{check_city} -> all except {abs(cities[check_city] - value)} accommodated")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement