Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- targets = {}
- while True:
- data = input().split("||")
- if data[0] == "Sail":
- break
- city = data[0]
- population, gold = int(data[1]), int(data[2])
- if city not in targets:
- targets[city] = {"population": 0, "gold": 0}
- targets[city]["population"] += population
- targets[city]["gold"] += gold
- while True:
- command = input().split("=>")
- if command[0] == "End":
- break
- town = command[1]
- if command[0] == "Plunder":
- people, gold = int(command[2]), int(command[3])
- targets[town]["population"] -= people
- targets[town]["gold"] -= gold
- print(f"{town} plundered! {gold} gold stolen, {people} citizens killed.")
- if targets[town]["population"] <= 0 or targets[town]["gold"] <= 0:
- del targets[town]
- print(f"{town} has been wiped off the map!")
- elif command[0] == "Prosper":
- gold = int(command[2])
- if gold < 0:
- print("Gold added cannot be a negative number!")
- else:
- targets[town]["gold"] += gold
- print(f"{gold} gold added to the city treasury. {town} now has {targets[town]['gold']} gold.")
- if not targets:
- print("Ahoy, Captain! All targets have been plundered and destroyed!")
- else:
- sorted_targets = sorted(targets.items(), key=lambda kvp: (-kvp[1]['gold'], kvp[0]))
- print(f"Ahoy, Captain! There are {len(targets)} wealthy settlements to go to:")
- for town_, data_ in sorted_targets:
- print(f"{town_} -> Population: {data_['population']} citizens, Gold: {data_['gold']} kg")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement