0
How to find max and min of a list using a recurring function
By recurring function I mean a function that works like a loop: the one that calls herself at the end... PS: i know the name in frensh as "fonction récursive" but i am not sure regarding its technical name in english 🤔 Please help, if u understood my unclear question of course 😅
15 Answers
+ 3
So here is mine pretty ugly but still working solution:
https://code.sololearn.com/cz66oXF1G3bQ/?ref=app
Also has error catching
Btw. it uses similar principle as your loop code just put to recursion
Pls. all comment any error, i am interested in this one
+ 3
In python it doesn't require to use recursive function. It had functions max() and min(). These return respectively maximal and manimal value from list passed as argument.
+ 2
It is called recursive function
And in what language, becase some of them have predefined functions for this
+ 2
If you had to use a loop instead of a recursive function, could you solve it yourself?
+ 2
mayssa rekik so do if it is homework show us your attempt to solve it. This is rules here.
+ 1
Oh ok thanks
I want it in python
+ 1
Jared Bird
Yes of course i've already done that before
L=list(input('write a numeric list')
Max =L[0]
While i in range(len(L)) :
If L[i] >Max :
Max=L[i]
Print(Max)
+ 1
Ok, so one way would be close to this. Could you write a function that removes 1 item from the list, then calls it's self until there is 1 left and this is the max?
+ 1
@maneren
Here is my attempt to code it using a recursive function
Def max (L) :
If L==0:
return 0
return max(L.del(L[0]))
+ 1
Maneren you ready to give the answer away already? BTW it does not work for a list of negative integers.
+ 1
Jared Bird oh i forgot it is Python and not Javascript. And what is the problem with answering?
+ 1
Maneren I hope you are not taking it personally. It's just when it's for some else's home work I prefer to give hints and not write the code for them.
+ 1
Jared Bird ok, get it and no problem i am just little bit more straightforward
PS. i gave just the idea, as you mentioned it doesn't work for negative, and also is just for max not min
So asker has to work on it little bit
+ 1
Jared Bird Maneren
Thanks a lot guys you've been really helpful 😁😄
0
Yes i do know that but i am asked to code a function that does the same thing of a pre-defined function
PS it's a homework 😐