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
CodePudding user response:
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))
CodePudding user response:
Min finds the minimum value in an iterable e.g. a list, min([1,2,3,4]) You are trying to find the minimum value of a single integer i.e. min(1) because the loop returns each value from the range of values you are iterating through