+ 3

WHY IS THIS WRONG?

def my_min(*x): for i in x: for a in x: if i < a: continue elif i >= a: return my_min(x[a:]) return i print(my_min(8, 13, 4, 42, 120, 7))

19th Jul 2022, 2:24 PM
Alex
Alex - avatar
15 Respuestas
+ 7
here is a solution with a simple for loop that is working: def get_min(nums_tup): min_ = a[0] for num in a: if num < min_: min_ = num return min_ print(get_min((18, 4,32,10,1, -1,55,100,11)))
19th Jul 2022, 7:12 PM
Lothar
Lothar - avatar
+ 4
FF9900 , can you please enlighten me why > ox = 2^32 is used? the expression results in: *34* and i also would like to ask why the values in the tuple > a =(184, 41,320,100,99, 1111,55,100,110) is giving a result of *34* as the minimum element, even is this elemrnt is not existing?
19th Jul 2022, 7:03 PM
Lothar
Lothar - avatar
+ 4
FF9900 , despite of the correction you made in the code, the error remains if the numbers in the tuple are greater than 2**32.
19th Jul 2022, 7:24 PM
Lothar
Lothar - avatar
+ 1
Ahhh yes, much simpler, many thanks :)
19th Jul 2022, 2:53 PM
Alex
Alex - avatar
+ 1
FF9900 be careful translating from C into Python. Whereas C has limited integer range, there is no definitive MAX_INT in Python 3.
20th Jul 2022, 4:39 AM
Brian
Brian - avatar
+ 1
👍
20th Jul 2022, 5:02 PM
Jakhongir Normuratov
Jakhongir Normuratov - avatar
0
Yep, in the tuple. I figured out whts wrojg though i think
19th Jul 2022, 2:37 PM
Alex
Alex - avatar
0
I know that a min() function exists, i just wanted to sus out what that actually was—-> def my_min(*x): for i in x: for a in x: if i < a: continue elif i >= a: i = a continue return i print(my_min(8, 13, 4, 42, 120, 7))
19th Jul 2022, 2:49 PM
Alex
Alex - avatar
0
This works
19th Jul 2022, 2:49 PM
Alex
Alex - avatar
0
I believe
19th Jul 2022, 2:49 PM
Alex
Alex - avatar