Advertisement
pacho_the_python

Untitled

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