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.
Numbers= [10, 20, 300, -1, -5, 1] MIN= Numbers  # 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)
Please help find a mistake
Answer # 1
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  For Elem in Numbers: MIN= Minimun (Min, Elem) PRINT (MIN)
Answer # 2
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  For i in my_list: minm= min_abl (MINM, I) Return minm. Print ("min=", min_el (my_list))
- python : Make a deep-on list flat without branching and cycles
- python : Summation by Vector NUMPY Indexes
- python : How to create a XLSL for each user from the SQL query?
- python : Line check lists
- python : Outputting the opposite value from the list
- python : Method simple permutation
- python : Parly withdraw elements of two or more lists
- python : Error 'list' is not callable for no apparent reason
- python : How to get rid of nesting when iterating over lists
- There are two variables with a dictionary and a vocabulary with an embedded list. How to write a feature in Python?