Question: PYTHON: Write a function first_half that takes a list and returns a new list (use the slice operator) with just the items from the first

PYTHON:

Write a function first_half that takes a list and returns a new list (use the slice operator) with just the items from the first half of the original list. For example, first_half([1,2,3,4]) would return [1, 2] and first_half([7,8,9]) should return [7].

PYTHON: Write a function first_half that takes a list and returns a

Write a function first_half that takes a list and returns a new list (use the slice operator) with just the items from the first half of the original list. For example, first_half([1,2,3,4]) would return (1, 2] and first_half([7,8,9]) should return [7]. Save & Run 1/31/2021, 11:53:12 PM - 43 of 51 1 def first_half(alist): 2 return alist[:2] 3 Activity: 4.20.4.4 ActiveCode (fuct_ac_list_first_half) Result Actual Value Expected Value Notes Pass [1, 2] [1, 2] first_half([1,2,3,4]) Fail [7,8] [7] first_half([7,8,9]) Pass 0 first_half(I) Fail [6] 0 first_half([6]) Pass [1, 2] [1, 2] first_half([1,2,3,4,5)) Fail [1, 2] [1, 2, 3] first_half([1,2,3,4,5,6]) You passed: 50.0% of the tests

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 Databases Questions!