Advertisement
horozov86

world tour

Mar 22nd, 2023
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. first_line = input()
  2.  
  3. while True:
  4.     line = input()
  5.     if line == "Travel":
  6.         break
  7.  
  8.     line_split = line.split(":")
  9.     command = line_split[0]
  10.  
  11.     if command == "Add Stop":
  12.         given_index = int(line_split[1])
  13.         new_stop = line_split[2]
  14.         if 0 <= given_index <= len(first_line):
  15.             first_line = (first_line[:given_index] + new_stop + first_line[given_index:])
  16.             print(first_line)
  17.  
  18.     elif command == "Remove Stop":
  19.         start_idx = int(line_split[1])
  20.         end_idx = int(line_split[2])
  21.         if 0 <= start_idx <= len(first_line) and 0 <= end_idx <= len(first_line):
  22.             first_line = (first_line[:start_idx]) + first_line[end_idx + 1:]
  23.             print(first_line)
  24.     else:
  25.         old_stop = line_split[1]
  26.         new_stop = line_split[2]
  27.         first_line = first_line.replace(old_stop, new_stop)
  28.         print(first_line)
  29.  
  30. print(f"Ready for world tour! Planned stops: {first_line}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement