Advertisement
Guest User

Untitled

a guest
Jul 27th, 2023
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.63 KB | None | 0 0
  1. def add_stop(destinations, command):
  2.     index = int(command[1])
  3.     new_stop = command[2]
  4.  
  5.     if index < len(destinations):
  6.         first_part = destinations[:index] + new_stop
  7.         second_part = destinations[index:]
  8.         destinations = first_part + second_part
  9.         return destinations
  10.     return destinations
  11.  
  12.  
  13. def remove_stop(destinations, command):
  14.     start_index = int(command[1])
  15.     end_index = int(command[2])
  16.  
  17.     if start_index < len(destinations) and end_index < len(destinations):
  18.         first_part = destinations[:start_index]
  19.         second_part = destinations[end_index + 1:]
  20.         destinations = first_part + second_part
  21.         return destinations
  22.     return destinations
  23.  
  24.  
  25. def switch_stops(destinations, command):
  26.     old_destination = command[1]
  27.     new_destination = command[2]
  28.  
  29.     if old_destination in destinations:
  30.         return destinations.replace(old_destination, new_destination)
  31.     return destinations
  32.  
  33.  
  34. initial_destinations = input()
  35. command = input()
  36.  
  37. while command != 'Travel':
  38.     command = command.split(':')
  39.     action = command[0]
  40.  
  41.     if action == 'Add Stop':
  42.         initial_destinations = add_stop(initial_destinations, command)
  43.         print(initial_destinations)
  44.  
  45.     elif action == 'Remove Stop':
  46.         initial_destinations = remove_stop(initial_destinations, command)
  47.         print(initial_destinations)
  48.  
  49.     elif action == 'Switch':
  50.         initial_destinations = switch_stops(initial_destinations, command)
  51.         print(initial_destinations)
  52.  
  53.     command = input()
  54.  
  55. print(f'Ready for world tour! Planned stops: {initial_destinations}')
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement