DiYane

P!rates/old

Sep 18th, 2023
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.61 KB | None | 0 0
  1. cities = {}
  2.  
  3. command = input()
  4.  
  5. while command != "Sail":
  6.     tokens = command.split("||")
  7.     town = tokens[0]
  8.     people = int(tokens[1])
  9.     gold = int(tokens[2])
  10.  
  11.     if town not in cities.keys():  # town not in cities (същото е)
  12.         cities[town] = [people, gold]
  13.     else:
  14.         cities[town][0] += people
  15.         cities[town][1] += gold
  16.     command = input()
  17.  
  18. command = input()
  19. while command != "End":
  20.     tokens = command.split("=>")
  21.     cmd = tokens[0]
  22.  
  23.     if cmd == "Plunder":
  24.         town = tokens[1]
  25.         people = int(tokens[2])
  26.         gold = int(tokens[3])
  27.  
  28.         cities[town][0] -= people
  29.         cities[town][1] -= gold
  30.         print(f'{town} plundered! {gold} gold stolen, {people} citizens killed.')
  31.  
  32.         if cities[town][0] <= 0 or cities[town][1] <= 0:
  33.             cities.pop(town)
  34.             print(f'{town} has been wiped off the map!')
  35.  
  36.     elif cmd == "Prosper":
  37.         town = tokens[1]
  38.         gold = int(tokens[2])
  39.  
  40.         if gold < 0:
  41.             print(f'Gold added cannot be a negative number!')
  42.         else:
  43.             cities[town][1] += gold
  44.             print(f'{gold} gold added to the city treasury. {town} now has {cities[town][1]} gold.')
  45.     command = input()
  46.  
  47. if len(cities) > 0:  # if cities (същото е)
  48.  
  49.     print(f'Ahoy, Captain! There are {len(cities)} wealthy settlements to go to:')
  50.  
  51.  
  52.     for key, value in sorted(cities.items(), key=lambda x: (-x[1][1], x[0])):
  53.         print(f'{key} -> Population: {value[0]} citizens, Gold: {value[1]} kg')
  54.  
  55. else:
  56.     print(f'Ahoy, Captain! All targets have been plundered and destroyed!')
Tags: python
Add Comment
Please, Sign In to add comment