Why is my python program not running the code in the right order? -


i started out in python , programming hangman game base on book. may know why code below not running in order want run?

when execute program, letter guessed in guess suppose go used indicate letters has player guessed find out right word. however, happens every 2 turns , not every 1 turn. i've indicated hangman acsii art @ start of program in image file reference, below image code. gladly appreciate help. thanks!

enter image description here

max_wrong = len(hangman)-1  words = ("book","toy","paper","school","house","computer","television") word=random.choice(words) so_far = "-"*len(word) wrong = 0 used = []  print "welcome hangman! guess the word before the man hang      dead!" print "you can guess 1 letter @ time!"  while wrong < max_wrong , so_far!=word:     print hangman[wrong]     print "\nyou've used following letters:\n",used     print "\nso far, word is:\n", so_far     guess = raw_input("\n\nenter guess:")     guess = guess.lower()      if guess in word:         used+=guess         print "\nyou've used following letters:\n",used         print"\nyes!",guess,"is in word!"         new=""         in range(len(word)):             if guess == word[i]:                 new+=guess             else:                 new+=so_far[i]         so_far=new      else:         used+=guess         print "\nyou've used following letters:\n",used         print "\nso far, word is:\n", so_far         print"\nsorry,",guess,"isn't in word."         guess = raw_input("\n\nenter guess:")         wrong+=1      while guess in used:         print "you've guessed letter:",guess         print "\nyou've used following letters:\n",used         print "\nso far, word is:\n", so_far         guess = raw_input("enter guess:")         guess = guess.lower  if wrong == max_wrong:     print hangman[wrong]     print "\nyou've been hanged!" else:     print "\nyou guessed it!"  print "\nthe word was",word  raw_input("\n\npress enter key exit.") 

it appears happening 2 turns, not case. problem program prompts user twice in single turn. @ start of loop ask user letter. if tell me wrong, ask letter. loop repeats , ask letter again.

the problem asking letter twice within loop, not once. in programming have called dry principle means don't repeat yourself. code shows 1 of many reasons not repeat yourself. thought loop running twice, running same code multiple times in loop.


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -