Search code examples
pythonfor-loopminimum

How do you use for loop to find the minimum without using something similar to "min" on Python?


This is what I have so far, but I would like to use it without min and with for loop:

Numbers = [100, 97, 72, 83, 84, 78, 89, 84, 83, 75, 54, 98, 70, 88, 99, 69, 70, 79, 55, 82, 81, 75, 54, 82, 56, 73, 90, 100, 94, 89, 56, 64, 51, 72, 64, 94, 63, 82, 77, 68, 60, 93, 95, 60, 77, 78, 74, 67, 72, 99, 93, 79, 76, 86, 87, 74, 82]

for i in range(len(Numbers)):
       print(min(Numbers))

Solution

  • Another identical method is:

    numbers = [100, 97, 72, 83, 84, 78, 89, 84, 83, 75, 54, 98, 70, 88, 99, 69, 70, 79, 55, 82, 81, 75, 54, 82, 56, 73, 90, 100, 94, 89, 56, 64, 51, 72, 64, 94, 63, 82, 77, 68, 60, 93, 95, 60, 77, 78, 74, 67, 72, 99, 93, 79, 76, 86, 87, 74, 82]
    
    smallest = None
    for x in range(len(numbers)):
        if (smallest == None or numbers[x] < smallest):
            smallest = numbers[x]
    print(smallest)
    

    Output:

    51