Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def add_stop(stops_str, idx, str):
- result = ''
- if idx in range(len(stops_str)):
- result = stops_str[:idx] + str + stops_str[idx:]
- print(result)
- return result
- def remove_stop(stops_str, start, stop):
- result = ''
- if start in range(len(stops_str)) and stop in range(len(stops_str)):
- result = stops_str[:start] + stops_str[stop + 1:]
- print(result)
- return result
- def switch(stops_str, old, new):
- try:
- if old in stops_str and old != new:
- result = stops_str.replace(old, new)
- print(result)
- except:
- print('error')
- return result
- stops = input()
- data = input()
- while not data == "Travel":
- splitted_data = data.split(':')
- command = splitted_data[0]
- if command == "Add Stop":
- index = int(splitted_data[1])
- string = splitted_data[2]
- stops = add_stop(stops, index, string)
- elif command == "Remove Stop":
- start_index = int(splitted_data[1])
- stop_index = int(splitted_data[2])
- stops = remove_stop(stops, start_index, stop_index)
- elif command == "Switch":
- old_string = splitted_data[1]
- new_string = splitted_data[2]
- stops = switch(stops, old_string, new_string)
- data = input()
- print(f"Ready for world tour! Planned stops: {stops}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement