Question: Starting Code def even_elements(input_list): output = [] #create an empty list for i in range(len(input_list)): #loop with i = 0 to len(input_list)-1 if(i % 2
Starting Code
def even_elements(input_list): output = [] #create an empty list for i in range(len(input_list)): #loop with i = 0 to len(input_list)-1 if(i % 2 == 0): #check whether i is even output.append(input_list[i]) #add ith element to the output input_list return output #return the output list even_vals = even_elements([2,3,4,5,6,7,8,9]) #call the function print(even_vals) #print the result
3) Finish the function that is started below. Make a new list # that contains in order from left to right every element of input_list # that has an even index number. # Return that new list. This is an example of an accumulation loop # Finish this function by replacing the return line with your own lines # of code. def even_elements(input_list): return "replace this line with your code" # The function is called with this data even_vals = even_elements([2,3,4,5,6,7,8,9]) print(even_vals) # The test code above should produce #[2, 4, 6, 8] # once you implement the function
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
