2013-03-29 5 views
0
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 

이것은 행맨 (hangman)을위한 일부 코드의 일부입니다. 이 오류가 라인 내에서 말한다 :IndexError : 목록 할당 색인이 범위를 벗어남. Python 3이 의미는 무엇이며 어떻게 수정합니까?

dash[count - 1] = letterGuess 

답변

0

그것은 countdash의 길이보다 큰 것을 의미한다. dash의 내용을 모르기 때문에 더 말하기 어렵습니다.

+0

대시에는 단어의 모든 문자에 대시가 포함되어 있어야하므로 단어가 'hiya'이면 대시가 '----'입니다. 감사! – zara

0

대시는 길이가 0이거나 iterable이 될 수 없습니다. 대시를 인쇄하고 eror를 발생시키는 줄은 올바르게 입력해야합니다.

관련 문제