SHARE
TWEET

Untitled

a guest Jan 23rd, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. city_data = {}
  2. command = input()
  3. while command != 'ready':
  4.     vehicles_data = {}
  5.     city_info = command.split(':')
  6.     city = city_info[0]
  7.     vehicles = city_info[1].split(",")
  8.     for item in vehicles:
  9.         vehicle = item.split('-')
  10.         vehicles_data[vehicle[0]] = int(vehicle[1])
  11.     if city not in city_data:
  12.         city_data[city] = vehicles_data
  13.     else:
  14.         city_data[city].update(vehicles_data)
  15.     command = input()
  16.  
  17. tourists_data = {}
  18. command = input()
  19. while command != 'travel time!':
  20.     tourists_info = command.split(' ')
  21.     tourists_data[tourists_info[0]] = int(tourists_info[1])
  22.     command = input()
  23.  
  24. total_vehicles_per_city = {}
  25. for key, value in city_data.items():
  26.     sum_vehicles = 0
  27.     for val in value.values():
  28.         sum_vehicles += val
  29.     total_vehicles_per_city[key] = sum_vehicles
  30.  
  31. for city_name, tourist_value in tourists_data.items():
  32.     for city, vehicles_num in total_vehicles_per_city.items():
  33.         if city_name == city:
  34.             if tourist_value <= vehicles_num:
  35.                 print(f'{city} -> all {tourist_value} accommodated')
  36.             else:
  37.                 diff = tourist_value - vehicles_num
  38.                 print(f'{city} -> all except {diff} accommodated')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top