0

I'm trying to return a range of Pokemon by their number using a CSV file, using a minimum and a maximum, so I want to change the numbers to an integer. So far, I have only been able to return one exact Pokemon if I don't take the inputs as an integer. My CSV is 801 lines long, poke[0] is their number, and poke[1] is their name.

def number(list):
  newlist = []
  x = 0
  q2 = int(input("Minimum number? "))
  q3 = int(input("Maximum number? "))
  for poke in range(1,800):
    poke[0] = int(poke[0])
  for poke in list:
    if poke[0] >= q2 and poke[0] <= q3:
      newlist.append(poke[0] + " " + poke[1])
  for poke in newlist:
    print(newlist[x])
    x = x + 1
  • Where is the code that reads from a csv file? – shahkalpesh Feb 08 '21 at 19:54
  • 1
    FYI you shouldn't literally name something `list` in Python since that's a built-in reserved word. More info: https://stackoverflow.com/questions/9109333/is-it-bad-practice-to-use-a-built-in-function-name-as-an-attribute-or-method-ide – Random Davis Feb 08 '21 at 19:58

1 Answers1

1

In the first loop, your are incrementing poke as an integer in range 1, 800. This integer can not be indexed.

pakpe
  • 5,391
  • 2
  • 8
  • 23