Epython Lab
#CODE_CHALLENGE_3 #LIST #SWAP_TWO_NUMBERS #Q: The next iteration of Asibeh Tenager will feature an extra-infuriating new item, the Purple Shell. When used, it warps the last place racer into first place and the first place racer into last place. Write a…
#Solution for #CODE_CHALLENGE_3
# Given a list of racers, set the first place racer (at the front of the list)
# Use swap mechanism
def purple_shell(lst):
# swap list items
temp = lst[0]
lst[0] = lst[2]
lst[2] = temp
return lst
# code driver
racers = ['Asibeh', 'Naol', 'Obang']
purple_shell(racers)
#Output: ['Obang', 'Naol', 'Asibeh']
# Given a list of racers, set the first place racer (at the front of the list)
# Use swap mechanism
def purple_shell(lst):
# swap list items
temp = lst[0]
lst[0] = lst[2]
lst[2] = temp
return lst
# code driver
racers = ['Asibeh', 'Naol', 'Obang']
purple_shell(racers)
#Output: ['Obang', 'Naol', 'Asibeh']