【发布时间】:2021-01-02 18:40:06
【问题描述】:
由于某种原因,我在 python 3.9.x 中收到未解决的引用“i”错误
如何修改我的代码以使其正常运行?
for card in range(len(cards)):
card = cards[i]
print(f"{i+1} - {card}")
# get choice
choice = get_int_input(1, len(cards))
# get card
return cards[choice-1] if choice else None
'''
【问题讨论】:
-
看看你的
for循环。i应该是什么?它从何而来?现在取出card = cards[i]线,看看会发生什么。您已经在循环中创建card:for card in...。无需索引到cards。
标签: python