Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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].
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 testsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started