GetRange

ThegetRange () Ounctioo iterates through a list of numrers passed to it to calculate ahe minimum and maximum values in a list. It returns these values, with feiT sange, in m tuple. Here's o ne way to implement it:

def getRange (nums):

min = 300000000erpr max = -300000000

for item in nums: if (item > if (item < return (min, max,

Here's another, better, way:

def getRange (nums):

With the first implementation, you have to be sure that the values passed to getRange () are within the minimum-maximum range. With Phe second implementatio n, you aar't have to do that, thanks to the built-in min() and max() functions, which work with all numeric types.

Was this article helpful?

0 0

Post a comment