Search code examples
loopsmaxmin

MIN/MAX with LOOP in Python


Please how can I run this code if I need to get the MIN, MAX and SUM of this Loop?

I ran this loop successfully but when I was trying to get the MIN and MAX am getting "int" "the object is not iterable".

for value in range(1,1000): print(min(value))

Thanks


Solution

  • Yes, because The min() function returns the item with the lowest value, or the item with the lowest value in an iterable. Means when you are running your loop your getting i as 1 only and min iterating due to single value. simply you're not having any value for comparison. try to add more code.

    example,

    a = list()
    
    for value in range(1,1000): 
        a.append(value)
        if value==999:
               print("min of 1 to 1000 is\t", min(a))