繁体   English   中英

IndexError:列表分配索引超出范围Python 3这是什么意思,我该如何解决?

[英]IndexError: list assignment index out of range Python 3 What does this mean and how do I fix it?

elif letterGuess in letterList: # if the letter is one the word characters
  count = 1
  print (letterGuess, ' is in the word!')
  for n in letterList:
      if n == letterGuess: # replaces the dashes with letters
          dash[count - 1] = letterGuess # takes the dash in position and replaces
      count += 1
  count = 0

这是子手某些代码的一部分。 它说错误在行内:

dash[count - 1] = letterGuess

这意味着count大于dash的长度。 由于我们不知道dash应该包含什么,因此很难多说。

破折号的长度只能为0或不可重复。在引起错误的行之前,请分别打印破折号和cout。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM