Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This question is driving me insane... i got this: [10, 50, 11, 100, 4, 5, 12] from the first example. however the expected output is

image text in transcribed

This question is driving me insane...

i got this: [10, 50, 11, 100, 4, 5, 12] from the first example. however the expected output is [10, 20, 50, 11, 100, 4, 5, 12]. I kinda get why my 20 is not showing, but I dont know how to fix it... Please help me

Write a function called get_elements_at_even(a_list) which takes a list as a parameter and returns a new list with only the elements at the even-numbered positions of the original list. i.e. elements at position 0, 2, 4, 6 ... of the original list. For example: st Result sult = get_elements_at_even([10, 20, 20, 30, 50, 60, 11, 18, 100, 15, 4, 200, 5, 85, 12, 60]) [10, 20, 50, 11, 100, 4, 5, 12] int(result) sult = get_elements_at_even([]) int(result) [10] sult = get_elements_at_even([10]) int(result) Answer: (penalty regime: 0, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 %) 1 def get_elements_at_even(a_list): alist = [] for i in a_list: 41 if a_list == [] : return [] 2 elif a_list.index(i) == 0: alist.append(i) elif a_list.index(i)%2==0: alist.append(i) return alist

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

More Books

Students also viewed these Databases questions