Advertisement
Guest User

world_tour

a guest
Aug 9th, 2020
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. def valid_idx(i, my_string):
  2.     return i in range(len(my_string))
  3.  
  4.  
  5. stops = input()
  6.  
  7. while True:
  8.     line = input().split(':')
  9.     command = line[0]
  10.  
  11.     if command == 'Travel':
  12.         break
  13.  
  14.     if command == 'Add Stop':
  15.         idx, stop = int(line[1]), line[2]
  16.         if valid_idx(idx, stops):
  17.             stops = stops[:idx] + stop + stops[idx:]
  18.         print(stops)
  19.     elif command == 'Remove Stop':
  20.         start_idx, end_idx = int(line[1]), int(line[2])
  21.         if valid_idx(start_idx, stops) and valid_idx(end_idx, stops):
  22.             stops = stops[:start_idx] + stops[end_idx + 1:]
  23.         print(stops)
  24.     elif command == 'Switch':
  25.         old_string, new_string = line[1], line[2]
  26.         if old_string in stops:
  27.             stops = stops.replace(old_string, new_string)
  28.         print(stops)
  29.  
  30. print(f'Ready for world tour! Planned stops: {stops}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement