viligen

p!rates

Nov 28th, 2021
704
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. targets = {}
  3. while True:
  4.     data = input().split("||")
  5.     if data[0] == "Sail":
  6.         break
  7.     city = data[0]
  8.     population, gold = int(data[1]), int(data[2])
  9.     if city not in targets:
  10.         targets[city] = {"population": 0, "gold": 0}
  11.     targets[city]["population"] += population
  12.     targets[city]["gold"] += gold
  13.  
  14. while True:
  15.     command = input().split("=>")
  16.     if command[0] == "End":
  17.         break
  18.     town = command[1]
  19.     if command[0] == "Plunder":
  20.         people, gold = int(command[2]), int(command[3])
  21.         targets[town]["population"] -= people
  22.         targets[town]["gold"] -= gold
  23.         print(f"{town} plundered! {gold} gold stolen, {people} citizens killed.")
  24.         if targets[town]["population"] <= 0 or targets[town]["gold"] <= 0:
  25.             del targets[town]
  26.             print(f"{town} has been wiped off the map!")
  27.     elif command[0] == "Prosper":
  28.         gold = int(command[2])
  29.         if gold < 0:
  30.             print("Gold added cannot be a negative number!")
  31.         else:
  32.             targets[town]["gold"] += gold
  33.             print(f"{gold} gold added to the city treasury. {town} now has {targets[town]['gold']} gold.")
  34. if not targets:
  35.     print("Ahoy, Captain! All targets have been plundered and destroyed!")
  36. else:
  37.     sorted_targets = sorted(targets.items(), key=lambda kvp: (-kvp[1]['gold'], kvp[0]))
  38.     print(f"Ahoy, Captain! There are {len(targets)} wealthy settlements to go to:")
  39.     for town_, data_ in sorted_targets:
  40.         print(f"{town_} -> Population: {data_['population']} citizens, Gold: {data_['gold']} kg")
  41.  
RAW Paste Data