Advertisement
DiYane

World tour

Sep 16th, 2023
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. def add_stop(stops_str, idx, str):
  2.     if idx in range(len(stops_str)):
  3.         return stops_str[:idx] + str + stops_str[idx:]
  4.     return stops_str
  5.  
  6.  
  7. def remove_stop(stops_str, start, stop):
  8.     if start in range(len(stops_str)) and stop in range(len(stops_str)):
  9.         return stops_str[:start] + stops_str[stop + 1:]
  10.     return stops_str
  11.  
  12.  
  13. def switch(stops_str, old, new):
  14.     return stops_str.replace(old, new)
  15.  
  16.  
  17. stops = input()
  18.  
  19. while True:
  20.     data = input()
  21.    
  22.     if data == "Travel":
  23.         break
  24.  
  25.     split_data = data.split(':')
  26.     command = split_data[0]
  27.  
  28.     if command == "Add Stop":
  29.         index = int(split_data[1])
  30.         string = split_data[2]
  31.         stops = add_stop(stops, index, string)
  32.     elif command == "Remove Stop":
  33.         start_index = int(split_data[1])
  34.         stop_index = int(split_data[2])
  35.         stops = remove_stop(stops, start_index, stop_index)
  36.     elif command == "Switch":
  37.         old_string = split_data[1]
  38.         new_string = split_data[2]
  39.         stops = switch(stops, old_string, new_string)
  40.  
  41.     print(stops)
  42.  
  43. print(f"Ready for world tour! Planned stops: {stops}")
Tags: python
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement