Advertisement
bl00dt3ars

03. P!rates

Jun 27th, 2021
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.62 KB | None | 0 0
  1. targeted_cities = {}
  2.  
  3. data = input()
  4. while not data == "Sail":
  5.     town, people, gold = data.split("||")
  6.     people = int(people)
  7.     gold = int(gold)
  8.  
  9.     if town not in targeted_cities:
  10.         targeted_cities[town] = [0, 0]
  11.     targeted_cities[town][0] += people
  12.     targeted_cities[town][1] += gold
  13.     data = input()
  14.  
  15. line = input()
  16. while not line == "End":
  17.     line = line.split("=>")
  18.     command = line[0]
  19.     town = line[1]
  20.     if command == "Prosper":
  21.         gold = int(line[2])
  22.         if gold > 0:
  23.             targeted_cities[town][1] += gold
  24.             print(f"{gold} gold added to the city treasury. {town} now has {targeted_cities[town][1]} gold.")
  25.         else:
  26.             print("Gold added cannot be a negative number!")
  27.     elif command == "Plunder":
  28.         people = int(line[2])
  29.         gold = int(line[3])
  30.         print(f"{town} plundered! {gold} gold stolen, {people} citizens killed.")
  31.         targeted_cities[town][0] -= people
  32.         targeted_cities[town][1] -= gold
  33.         if targeted_cities[town][0] <= 0 or targeted_cities[town][1] <= 0:
  34.             targeted_cities.pop(town)
  35.             print(f"{town} has been wiped off the map!")
  36.     line = input()
  37.  
  38. targeted_cities = dict(sorted(targeted_cities.items(), key=lambda x: (-x[1][1], x)))
  39. if len(targeted_cities) > 0:
  40.     print(f"Ahoy, Captain! There are {len(targeted_cities)} wealthy settlements to go to:")
  41.     for town in targeted_cities:
  42.         print(f"{town} -> Population: {targeted_cities[town][0]} citizens, Gold: {targeted_cities[town][1]} kg")
  43. else:
  44.     print("Ahoy, Captain! All targets have been plundered and destroyed!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement