Hi, can any one help me analyse the python funciton? Please find attached.
The function takes in a collection of numbers, ints, and returns the maximum and the minimum values within that collection.
how should I start to write this code? I have no idea...
Use a loop or recusion inside the funtion to see what is lowest and highest. You just check each value against some high/low variable and see if it is higher than the high or lower than the low. if so, change the high and the low.
how? I can't use max and min inbuilt function. I'd like to approach this using another loop
You can loop through your input (#,#,#,#) thing using the iterators: ``` max_and_min(numbers) max = None min = None for i in numbers: do your evaluations inside this loop to change max and min return(max,min) ```
In fact, rather than none, you could just set them to the first value in numbers. It does not matter what value they start with as long as it is not higer than the highest or lower than the lowest.
Did it in 7 lines in a loop. 20 in a recusion. And if you know comprehension, those would probably do it in 2 lines (the call, then the return with embedded comprehensions to do the evaluations).
I see. Let me try. thanks
I get it.thanks!
np. Have fun!
Here was my ugly recursion if you want to see how that worked. http://dpaste.com/hold/1392489/
Join our real-time social learning platform and learn together with your friends!