How to seperate a list and have it continue onto a different line?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Fuugie
    New Member
    • Sep 2010
    • 32

    #1

    How to seperate a list and have it continue onto a different line?

    I am currently having trouble trying to get my code to continue onto the next line and have my code still work properly.

    This is my code as of right now:
    Code:
    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']
    
    word = choice(wordChoices)
    wordLen = len(word)
    guesses = wordLen * ['_']
    maxIncorrect = 6
    alphabet= 'abcdefghijklmnopqrstuvxyz'
    lettersTried = ''
    numberGuesses = 0
    lettersCorrect = 0
    incorrectGuesses = 0
    
    
    printGameRules(maxIncorrect, wordLen)
    
    while (incorrectGuesses != maxIncorrect) and (lettersCorrect != wordLen):
        letter = getLetter()
        if len(letter)==1 and letter.isalpha():
            if letters_tried.find(letter) != -1:
                print "You already picked", letter
            else:
                lettersTried = lettersTried + letter
                firstIndex = word.find(letter)
                if  firstIndex == -1:
                    incorrectGuesses = incorrectGuesses +1
                    print "The",letter,"is not the mystery word"
                else:
                    print"The",letter,"is in the mystery word"
                    lettersCorrect = lettersCorrect+1
                    for i in range(wordLen):
                        if letter == word[i]:
                            guesses[i] = letter
    
        else:
            print "Please guess a single letter in the alphabet."
        hangmanPics(incorrectGuesses)
        
        print ''.join(guesses)
        print "Letters tried so far: ", lettersTried
        if incorrectGuesses == maxIncorrect:
            print "Sorry, too many incorrect guesses. You are hanged."
            print "the word was",word
        if lettersCorrect == wordLen:
            print "You guessed all the letters in the word!"
            print "the word was",word
    
    raw_input()
    Any help would be much appreciated
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    I cannot tell what your problem is just by looking at the posted code. Since the posted code is incomplete, I cannot test it. Please be more specific or post enough code so it can be tested.

    Comment

    • dwblas
      Recognized Expert Contributor
      • May 2008
      • 626

      #3
      Code:
              word_list = list(word)
              ...... code in between removed
              for i in range(wordLen):
                  if letter == word_list[i]:
                      guesses[i] = letter
                      word_list[i] = "*"
      Note that for 'baboon', if you want to only replace one letter at a time, replace found letters with "*" so the same letter won't be found a second time.

      Comment

      Working...