Advertisement
horozov86

P!rates

Mar 23rd, 2023
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.63 KB | None | 0 0
  1. cities = {}
  2.  
  3. while True:
  4.     data = input()
  5.     if data == "Sail":
  6.         break
  7.  
  8.     data_split = data.split("||")
  9.     city = data_split[0]
  10.     population = int(data_split[1])
  11.     gold = int(data_split[2])
  12.  
  13.     if city not in cities:
  14.         cities[city] = {"population": population, "gold": gold}
  15.     else:
  16.         cities[city]["population"] += population
  17.         cities[city]["gold"] += gold
  18.  
  19. while True:
  20.     line = input()
  21.     if line == "End":
  22.         break
  23.  
  24.     line_split = line.split("=>")
  25.     command = line_split[0]
  26.     city = line_split[1]
  27.  
  28.     if command == "Plunder":
  29.         people = int(line_split[2])
  30.         gold = int(line_split[3])
  31.  
  32.         cities[city]["population"] -= people
  33.         cities[city]["gold"] -= gold
  34.         print(f"{city} plundered! {gold} gold stolen, {people} citizens killed.")
  35.  
  36.         if cities[city]["population"] <= 0 or cities[city]["gold"] <= 0:
  37.             del cities[city]
  38.             print(f"{city} has been wiped off the map!")
  39.  
  40.     else:
  41.         gold = int(line_split[2])
  42.  
  43.         if gold < 0:
  44.             print(f"Gold added cannot be a negative number!")
  45.             continue
  46.         else:
  47.             cities[city]["gold"] += gold
  48.             print(f"{gold} gold added to the city treasury. {city} now has {cities[city]['gold']} gold.")
  49.  
  50. if not cities:
  51.     print("Ahoy, Captain! All targets have been plundered and destroyed!")
  52. else:
  53.     print(f"Ahoy, Captain! There are {len(cities)} wealthy settlements to go to:")
  54.     for city, values in cities.items():
  55.         print(f"{city} -> Population: {cities[city]['population']} citizens, Gold: {cities[city]['gold']} kg")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement