【发布时间】:2023-03-20 11:15:02
【问题描述】:
我正在尝试使用 CSV 文件返回一系列口袋妖怪的编号,使用最小值和最大值,所以我想将数字更改为整数。到目前为止,如果我不将输入作为整数,我只能返回一个精确的口袋妖怪。我的 CSV 有 801 行长,poke[0] 是他们的编号,poke[1] 是他们的名字。
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
【问题讨论】:
-
从 csv 文件读取的代码在哪里?
-
仅供参考,您不应该在 Python 中直接命名
list,因为这是一个内置的保留字。更多信息:stackoverflow.com/questions/9109333/…