[英]How to fix “IndexError: list assignment index out of range” error in Python?
[英]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.