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))
4 Answers
+ 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))
+ 1
print(sorted((map(lambda x: int(x),input().split(','))))[0])
just enter numbers separated by comma
input: 12,5,46,7,0
+ 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>?
+ 1
Thank you!! It took me great amount of hours to figure out..failed then asked question!! Thank you for your continued support!!đ