Write a function called midway()
that will return the middle number in a list.
The function will receive a Python list
passed in as a parameter. The middle number is the number halfway through the list. In Python, the len()
function will return the length of a list. For example:
len( [87, 34, 58, 9, 34, 97, 23] )
returns 7
because there are 7 values in the listYou may assume that the list will always have at least two values. If the list doesn't contain an odd number of items, you may return either of the "middle" numbers.
Examples:
midway( [1, 2, 3, 4, 5] )
returns 3
midway( [87, 34, 58, 9, 34, 97, 23] )
returns 9
midway( [10, 7, 8, 10] )
can return either 7
or 8
©2017 Graham Mitchell