Advertisement
BdW44222

Problem 1. World Tour

Aug 9th, 2021
875
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. def print_state(stops_info):
  2.     return stops_info
  3.  
  4.  
  5. data = input()
  6. stops = " "
  7.  
  8. while not data == "Travel":
  9.     command = data.split(":")[0]
  10.  
  11.     if command == "Add Stop":
  12.         index = int(data.split(":")[1])
  13.         next_stop = data.split(":")[2]
  14.         if 0 <= index < len(stops):
  15.             left_side = stops[:index]
  16.             right_side = stops[index:]
  17.             stops = left_side + next_stop + right_side
  18.             print(print_state(stops))
  19.  
  20.     elif command == "Remove Stop":
  21.         start_index = int(data.split(":")[1])
  22.         end_index = int(data.split(":")[2])
  23.         if 0 <= start_index < len(stops) and 0 <= end_index < len(stops):
  24.             left_side = stops[:start_index]
  25.             right_side = stops[end_index + 1:]
  26.             stops = left_side + right_side
  27.             print(print_state(stops))
  28.  
  29.     elif command == "Switch":
  30.         old_string = data.split(":")[1]
  31.         new_string = data.split(":")[2]
  32.         if old_string in stops:
  33.             stops = stops.replace(old_string, new_string)
  34.         print(print_state(stops))
  35.  
  36.     else:
  37.         stops = data
  38.  
  39.     data = input()
  40.  
  41. print(f"Ready for world tour! Planned stops: {stops}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement