Home>

### It is necessary to find the minimum value in the list in Python 3. Help find a mistake

Task: Create a Minimun feature that takes two arguments (def minimum (x, y): ...) and returning minimum of them; Using this function inside the cycle, find the minimum value in the Numbers list.

My code:

``````Numbers= [10, 20, 300, -1, -5, 1]
MIN= Numbers [0]
# Create a function
Def Minimum (Min, Y):
IF min >
y:
MIN= Y.
# I find the smallest in the list
For n in numbers:
Minimum (MIN, N)
# Print the smallest in the list
PRINT (MIN)
``````

You have a mistake because the arguments are transmitted by the value
Only changeable data types (lists, dictionaries, etc.) are transmitted by reference. The solution here is just a little to correct your feature minimum :

``````Def Minimun (A, B):
RETURN A IF A <
B ELSE B.
Numbers= [10, 20, 300, -1, -5, 1]
MIN= Numbers [0]
For Elem in Numbers:
MIN= Minimun (Min, Elem)
PRINT (MIN)
``````

It should be noted that MIN is the name of the built-in function of python, it is better not to use such a variable name, it overlaps the built-in function.

CrazyElf2021-04-08 07:08:23
``````Import Random
My_List= [Random.randint (-20, 20) for i in Range (20)]
Def min_abl (A, B):
RETURN A IF A <
B ELSE B.
Def min_el (My_List):
MINM= My_List [0]
For i in my_list:
minm= min_abl (MINM, I)
Return minm.
Print ("min=", min_el (my_list))
``````

Welcome to this Club in Russian! Please leave a little more deployed answers. Try to tell about all the nuances that may arise when solving the problem according to your scenario. Present your suggestions. It is possible and a brief answer, but the more and more clear it will be outlined, the better. You can add the answer by clicking Edit

aleksandr barakin2021-04-08 07:06:18