By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,907 Members | 1,832 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,907 IT Pros & Developers. It's quick & easy.

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

P: 32
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:
Expand|Select|Wrap|Line Numbers
  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.  
Any help would be much appreciated
Nov 1 '10 #1
Share this Question
Share on Google+
2 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
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.
Nov 1 '10 #2

Expert 100+
P: 624
Expand|Select|Wrap|Line Numbers
  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] = "*" 
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.
Nov 1 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.