How do I calculate the two smallest numbers in an array? using a min only helps me to know the smallest not the two smallest
def minimo(a):
mini=a[0]
for m in range (len(n)):
if a[m]<mini:
mini=a[m]
return mini
How do I calculate the two smallest numbers in an array? using a min only helps me to know the smallest not the two smallest
def minimo(a):
mini=a[0]
for m in range (len(n)):
if a[m]<mini:
mini=a[m]
return mini
It may not be obvious but it is simpler than it seems, you just have to order the list from least to greatest and the first two elements are the two "least".
Code example: