0

Find lowest number in a list

Write a function which accepts an input list of numbers and returns the smallest number in the list (Do not use python's built-in min() function). If I use print function m_num = x(0) to get lowest number it is not working. Please Help!!! sample_list = [5,6,7,1,0,2] def min_num(x): e = [] m_num= x[0] for i in x: if i<m_num: e.append(i) return e print(min_num(sample_list))

7th Feb 2022, 3:54 AM
Knowledge Is Power
Knowledge Is Power - avatar
4 Respuestas
+ 4
Sorting isn't necessary. sample_list = [5,6,7,1,0,2] def min_num(x): min = x[0] for i in range(1,len(x)): if x[i] < min: min = x[i] return min print(min_num(sample_list))
7th Feb 2022, 5:21 AM
Avinesh
Avinesh - avatar
+ 1
print(sorted((map(lambda x: int(x),input().split(','))))[0]) just enter numbers separated by comma input: 12,5,46,7,0
7th Feb 2022, 4:10 AM
L.M.Paredes
L.M.Paredes - avatar
+ 1
def min_num( lst ): lst.sort() # sort it first, return lst[ 0 ] # then return the first element You said "returns the smallest number in the list ..." why you returned a new `list` <e>?
7th Feb 2022, 5:16 AM
Ipang
+ 1
Thank you!! It took me great amount of hours to figure out..failed then asked question!! Thank you for your continued support!!👍
7th Feb 2022, 6:54 PM
Knowledge Is Power
Knowledge Is Power - avatar