Question: solve coding problems data structures and algorithm problems YOU CANNOT USE ANY BUILT - IN FUNCTION EXCEPT len IN PYTHON. 1 . Merge Lineup: Now

solve coding problems data structures and algorithm problems
YOU CANNOT USE ANY BUILT-IN FUNCTION EXCEPT lenIN PYTHON.
1. Merge Lineup:
Now you guys are playing a 2v2 fierce pokemon battle. At one point your and your teammate's pokemons have very low hp. So you created a new rule to merge the hp of your and your teammate's pokemons and create a new pokemon lineup. But the opposite team placed a special condition. You and your teammate have to add the hp of your team's pokemons from opposite directions. That is, your first pokemon's hp will be added to your teammate's last pokemon's hp; your second pokemon's hp will be added to your teammate's second last pokemon's hp and so on and so forth. The None elements denote 0 hp. You and your teammate have the same number of pokemons. Implement the scenario using a proper method which takes your and your teammate's pokemon hp as two arrays (as parameters); and returns the resulting arr.
Sample Input / Driver Code:
pokemon_1: [4,5,-1, None, None]
pokemon_2: [2,27,7,12, None]
#Function Call: print(mergeLineup(pokemon_1, pokemon_2))
Sample Output:
[4,17,6,27,2]
#drivercode
def mergeLineup(pokemon_1, pokemon_2):
#To Do
print("///Task 01: Merge Lineup ///")
pokemon_1= np.array([12,3,25,1, None])
pokemon_2= np.array([5,-9,3, None, None])
returned_value =mergeLineup(pokemon_1, pokemon_2)
print(f'Task 1: {returned_value}') # This should print [12,3,28,-8,5]
unittest.output_test(returned_value, np.array([12,3,28,-8,5]))
pokemon_1= np.array([4,5,-1, None, None])
pokemon_2= np.array([2,27,7,12, None])
returned_value =mergeLineup(pokemon_1, pokemon_2)
print(f'Task 1: {returned_value}') # This should print [4,17,6,27,2]
unittest.output_test(returned_value, np.array([4,17,6,27,2]))
Explanation:
4+None(0)=4{pokemon_1[0]+pokemon_2[4]},
5+12=17{pokemon_1[1]+pokemon_2[3]},
-1+7=6{pokemon_1[2]+pokemon_2[2]},
None(0)+27=27{pokemon_1[3]+pokemon_2[1]},
None(0)+2=2{pokemon_1[4]+pokemon_2[0]}

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!