Advertisement
Guest User

Untitled

a guest
Aug 20th, 2020
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. cities = {}
  2.  
  3. command = input()
  4.  
  5. while command != "Sail":
  6. tokens = command.split("||")
  7. town = tokens[0]
  8. people = int(tokens[1])
  9. gold = int(tokens[2])
  10.  
  11. if town not in cities.keys():
  12. cities[town] = [people, gold]
  13. else:
  14. cities[town][0] += people
  15. cities[town][1] += gold
  16. command = input()
  17.  
  18. command = input()
  19. while command != "End":
  20. tokens = command.split("=>")
  21. cmd = tokens[0]
  22.  
  23. if cmd == "Plunder":
  24. town = tokens[1]
  25. people = int(tokens[2])
  26. gold = int(tokens[3])
  27.  
  28. if cities[town][0] - people > 0 and cities[town][1] - gold > 0:
  29. cities[town][0] -= people
  30. cities[town][1] -= gold
  31.  
  32. elif cities[town][0] - people < 0 or cities[town][1] - gold < 0:
  33. if cities[town][0] - people < 0:
  34. people = cities[town][0]
  35. cities[town][0] = 0
  36.  
  37. if cities[town][1] - gold < 0:
  38. gold = cities[town][1]
  39. cities[town][1] = 0
  40.  
  41. cities.pop(town)
  42. print(f'{town} has been wiped off the map!')
  43.  
  44. print(f'{town} plundered! {gold} gold stolen, {people} citizens killed.')
  45.  
  46. elif cmd == "Prosper":
  47. town = tokens[1]
  48. gold = int(tokens[2])
  49.  
  50. if gold < 0:
  51. print(f'Gold added cannot be a negative number!')
  52. continue
  53. else:
  54. cities[town][1] += gold
  55. print(f'{gold} gold added to the city treasury. {town} now has {cities[town][1]} gold.')
  56. command = input()
  57.  
  58. if len(cities) > 0:
  59.  
  60. print(f'Ahoy, Captain! There are {len(cities)} wealthy settlements to go to:')
  61.  
  62. for key, value in sorted(cities.items(), key= lambda x: (x[1], x), reverse=True):
  63. print(f'{key} -> Population: {value[0]} citizens, Gold: {value[1]} kg')
  64.  
  65. else:
  66. print(f'Ahoy, Captain! All targets have been plundered and destroyed!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement