Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def add_stop(destinations, command):
- index = int(command[1])
- new_stop = command[2]
- if index < len(destinations):
- first_part = destinations[:index] + new_stop
- second_part = destinations[index:]
- destinations = first_part + second_part
- return destinations
- return destinations
- def remove_stop(destinations, command):
- start_index = int(command[1])
- end_index = int(command[2])
- if start_index < len(destinations) and end_index < len(destinations):
- first_part = destinations[:start_index]
- second_part = destinations[end_index + 1:]
- destinations = first_part + second_part
- return destinations
- return destinations
- def switch_stops(destinations, command):
- old_destination = command[1]
- new_destination = command[2]
- if old_destination in destinations:
- return destinations.replace(old_destination, new_destination)
- return destinations
- initial_destinations = input()
- command = input()
- while command != 'Travel':
- command = command.split(':')
- action = command[0]
- if action == 'Add Stop':
- initial_destinations = add_stop(initial_destinations, command)
- print(initial_destinations)
- elif action == 'Remove Stop':
- initial_destinations = remove_stop(initial_destinations, command)
- print(initial_destinations)
- elif action == 'Switch':
- initial_destinations = switch_stops(initial_destinations, command)
- print(initial_destinations)
- command = input()
- print(f'Ready for world tour! Planned stops: {initial_destinations}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement