Question: can you help me with modify section function:modify _ section ( str , str , int, int ) - > str The first parameter represents

can you help me with modify section function:modify_section
(str, str, int, int)-> str
The first parameter represents the game state, the second parameter is the move to be applied to the string, the third parameter is the section number of the section to be modified, and the fourth parameter is the section length.
You may assume the move will be one of ROTATE or SWAP (the str value representing each can be seen in the constants provided for you at the top of the starter code) and that the third parameter is a valid section number.
This function will return a new string that reflects the updated game state after applying the given move to the specified section. For example, the function call modify_section('teerkocrlkae'def modify_section(game_state: str, move: str, section_num: int, section_length
: int)-> str:
""" Given a scrambled string, move, section number, and section length,
return a new string that reflects the updated game state after applying
the move to the specified section
>>> modify_section('teerkocrlake', 'SWAP', 2,4)
'teerrocklkae'
>>> modify_section('btuterfly', 'SWAP',2,2)
'butterfly'
>>> modify_section('ockrhill','R',2,4)
'rockhill'
"""
start = get_section_start(section_num, section_length)
end = start + section_length
if move == SWAP:
new_game_state = game_state[:start]+ game_state[end-1]
+ game_state[start+1:end-1]+ game_state[start:]+ game_state[end:]
elif move == ROTATE:
new_game_state = game_state[:start]+ game_state[end-1 : start:-1]
+ game_state[start]+ game_state[end:]
else :
new_game_state = game_state
return new_game_state
however neither swap or rotate seems to work pls help as asap with right code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!