Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python3 (2a) Write a function middle which takes a list L as its argument and returns the item in the middle position of L, when

python3

(2a) Write a function middle which takes a list L as its argument and returns the item in the middle position of L, when L has an odd length. Otherwise, middle should return 999999. For example, calling middle([8, 0, 100, 12, 18]) should return 100. You should, at least, have five different lists to test in the docstring: lists of even and odd number of numeric elements, lists of even and odd number of string elements, and a blank list. (Hint: you may use the // integer division operator).

(2b) Write a function, mySum, with one parameter, L, a list of numbers. mySum returns the sum of the numbers in the input list. (mySum should not use Pythons builtin sum function.) For example,

>>> mySum([2, 3, 2]) 7

In the docstring, there should be minimally five examples of function calls including a blank list, a single element list, and list of positive and negative numbers.

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

Step: 3

blur-text-image

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

Databases DeMYSTiFieD

Authors: Andy Oppel

2nd Edition

0071747990, 978-0071747998

More Books

Students also viewed these Databases questions

Question

do it with mouse hover

Answered: 1 week ago

Question

Detailed note on the contributions of F.W.Taylor

Answered: 1 week ago