-4

new to python just trying to figure out how to print the minimum of this generated list, but its giving me the error

TypeError: 'int' object is not iterable

and this is my code,

number = []
for number in range(1,21)
print min(number)

I have tried several things including

print(min(int(number))) 

Which seems like since its giving me an int problem would solve it, no?

  • 3
    Try `min(range(1,21))` to get the minimum of that list. `min` doesn't work on single ints. – slider Oct 13 '18 at 03:12

1 Answers1

0

for number in range(x, y) every number in that range represents a single int you cannot take the min of a single int. However you could append all those values to your empty list number and then take the min of that list, but even so we could just print the min of the entire range(x, y)

number = []
for i in range(1,21):
    number.append(i)
print(min(number)) # => 1

Or just using the range itself:

print(min(range(1, 12))) # => 1
vash_the_stampede
  • 4,590
  • 1
  • 8
  • 20