파이썬 에러질문..
글쓴이: 익명 사용자 / 작성시간: 화, 2018/01/23 - 10:55오전
import random HANGMANPICS = [''' +---+ | | | | | | ======== ''',''' +---+ | | 0 | | | | ======== ''',''' +---+ | | 0 | | | | | ========''',''' +---+ | | 0 | /| | | | ========''',''' +---+ | | 0 | /|\ | | | ========''',''' +---+ | | 0 | /|\ | / | | ========''',''' +---+ | | 0 | /|\ | / \ | | ========'''] words = 'ant banana fruit egg apple pineapple dog cobra coyote frog goat wolf whale turtle panda parrot shark seal rat tiger pie juice meet'.split() def getRandomWord(wordList): # wordIndex = random.randint(0, len(wordList) -1) return wordList[wordIndex] def displayBoard(HANGMANPICS, missedLetters, correctLetters, secretWord): print(HANGMANPICS[len(missedLetters)]) print() print('Missed letters:', end=' ') for letter in missedLetters: print(letter, end=' ') print() blanks = '_' * len(secretWord) for i in range(len(secretWord)): if secretWord[i] in correctLetters: blanks = blanks[:i] + secretWord[i] + blanks[i+1:] for letter in blanks: print(letter, end=' ') print() def getGuess(alreayGuessed): while True: print('Guess a letter.') guess = input() guess - guess.lower() if len(guess) != 1: print('Please enter a single letter.') elif guess in alreadtGuessed: print('You have already guessed that letter. Choose again.') elif guess not in 'abcdefghijklmnopqrstuvwxyz' : print('Please enter a LETTER.') else: return guess def playAgain(): print('Do you want to play again>(yes or no)') return input().lower().startswith('y') print('H A N G M A N') missedLetters = '' correctLetters = '' seceretWord = getRandomWord(words) gameIsDone = False while True: displayBoard(HANGMANPICS, missedLetters, correctLetters,secretWord)******** guess = getGuess(missedLetters + correctLetters) if guess in secretWord: correctLetters = correctLetters + guess foundAllLetters = True for i in range(len(secretWord)): if secretWord[i] not in correctLetters: foundAllLetters = False break if foundAllLetters: print('Yes! The secret word is"'+secretWord+'"! You have won!') gameIsDone = True else: missedLetters - missedLetters + guess if len(missedLetters) == len(HANGMANPICS) -1: displayBoard(HANGMANPICS, missedLetters, correctLetters, secretWord) print('You have run out of guesses!\nAfter ' + str(len(missedLetters))+' missed guesses and ' + str(len(correctLetters)) + ' correct guesses, the word was "' + secretWord +'"') gameIsDone = True if gameIsDone: if playAgain(): missedLetters = '' correctLetters = '' gameIsDone = False secretWord = getRandomWord(words) else: break
행맨게임코드인데 111줄(**로 표시해놨어요) 에서 secretWord가 선언되지않았다고 오류가뜨네요....
이게무슨..
Forums:
seceretWord / secretWord
seceretWord / secretWord
오타네요..
seceretWord = getRandomWord(words)
여기에서 seceretWord --> secretWord 로 변경하면 될듯요..
오... 고쳣습니다 감사합니다
오... 고쳣습니다 감사합니다
오... 고쳣습니다 감사합니다
오... 고쳣습니다 감사합니다
pycharm 써보세요.
pycharm 써보세요.
정말 좋은 IDE 더군요. 저런 에러 바로바로 잡아주기도 합니다.
댓글 달기