Advertisement
go6odn28

world_tour

Feb 29th, 2024
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. def check_index(index):
  2.     return 0 <= index < len(init_travel_stops)
  3.  
  4.  
  5. def add_stop(action, result):
  6.     idx = int(action[1])
  7.     if check_index(idx):
  8.         current_string = action[2]
  9.         result = result[:idx] + current_string + result[idx:]
  10.     return result
  11.  
  12.  
  13. def rem_stop(action, result):
  14.     idx1, idx2 = int(action[1]), int(action[2])
  15.     if check_index(idx1) and check_index(idx2):
  16.         result = result[:idx1] + result[idx2 + 1:]
  17.     return result
  18.  
  19.  
  20. def switch(action, result):
  21.     if action[1] in init_travel_stops:
  22.         result = result.replace(action[1], action[2])
  23.     return result
  24.  
  25.  
  26. init_travel_stops = input()
  27.  
  28. while True:
  29.     command = input().split(':')
  30.     if command[0] == "Travel":
  31.         print(f'Ready for world tour! Planned stops: {init_travel_stops}')
  32.         break
  33.  
  34.     if command[0] == 'Add Stop':
  35.         init_travel_stops = add_stop(command, init_travel_stops)
  36.     elif command[0] == 'Remove Stop':
  37.         init_travel_stops = rem_stop(command, init_travel_stops)
  38.     elif command[0] == 'Switch':
  39.         init_travel_stops = switch(command, init_travel_stops)
  40.     print(init_travel_stops)
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement