如何分隔列表并将其继续到另一行?

我目前在尝试让我的代码继续到下一行并使我的代码仍然正常工作时遇到了困难。
这是我目前的代码:

选择 | 换行 | 行号
  1. wordChoices = wordChoices = ['ant', 'baboon', 'badger', 'bat', 'bear', 'beaver', 'camel', 'cat', 'clam', 'cobra', 'cougar', 'coyote', 'crow','deer', 'dog', 'donkey', 'duck', 'eagle', 'ferret', 'fox', 'frog', 'goat', 'goose', 'hawk', 'lion', 'lizard', 'llama','mole', 'monkey', 'moose', 'mouse', 'mule', 'newt', 'otter', 'owl', 'panda', 'parrot', 'pigeon', 'python','rabbit', 'ram', 'rat', 'raven', 'rhino', 'salmon', 'seal', 'shark', 'sheep', 'skunk', 'sloth', 'snake', 'spider', 'stork', 'swan','tiger', 'toad', 'trout', 'turkey', 'turtle', 'weasel', 'whale', 'wolf', 'wombat', 'zebra']
  2.  
  3. word = choice(wordChoices)
  4. wordLen = len(word)
  5. guesses = wordLen * ['_']
  6. maxIncorrect = 6
  7. alphabet= 'abcdefghijklmnopqrstuvxyz'
  8. lettersTried = ''
  9. numberGuesses = 0
  10. lettersCorrect = 0
  11. incorrectGuesses = 0
  12.  
  13.  
  14. printGameRules(maxIncorrect, wordLen)
  15.  
  16. while (incorrectGuesses != maxIncorrect) and (lettersCorrect != wordLen):
  17.     letter = getLetter()
  18.     if len(letter)==1 and letter.isalpha():
  19.         if letters_tried.find(letter) != -1:
  20.             print "You already picked", letter
  21.         else:
  22.             lettersTried = lettersTried + letter
  23.             firstIndex = word.find(letter)
  24.             if  firstIndex == -1:
  25.                 incorrectGuesses = incorrectGuesses +1
  26.                 print "The",letter,"is not the mystery word"
  27.             else:
  28.                 print"The",letter,"is in the mystery word"
  29.                 lettersCorrect = lettersCorrect+1
  30.                 for i in range(wordLen):
  31.                     if letter == word[i]:
  32.                         guesses[i] = letter
  33.  
  34.     else:
  35.         print "Please guess a single letter in the alphabet."
  36.     hangmanPics(incorrectGuesses)
  37.  
  38.     print ''.join(guesses)
  39.     print "Letters tried so far: ", lettersTried
  40.     if incorrectGuesses == maxIncorrect:
  41.         print "Sorry, too many incorrect guesses. You are hanged."
  42.         print "the word was",word
  43.     if lettersCorrect == wordLen:
  44.         print "You guessed all the letters in the word!"
  45.         print "the word was",word
  46.  
  47. raw_input()
  48.  

如有任何帮助,将不胜感激

# 回答1


我不能仅仅通过查看发布的代码来判断您的问题所在。由于发布的代码不完整,我无法对其进行测试。请更具体或张贴足够的代码,以便它可以测试。
# 回答2

选择 | 换行 | 行号
  1.         word_list = list(word)
  2.         ...... code in between removed
  3.         for i in range(wordLen):
  4.             if letter == word_list[i]:
  5.                 guesses[i] = letter
  6.                 word_list[i] = "*" 

请注意,对于'Baboon',如果您一次只想替换一个字母,请将找到的字母替换为"*",这样相同的字母就不会再次被找到。

标签: python

添加新评论