Advertisement
koteshkoeziche

1. World Tour

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