I’m learning python using the Cory Alhoff’s “Self-taught Programmer”. I’ve gotten to the section of text based programming games and Hangman is used as an example but the code in the book doesn’t print anything when i replicate and run it. i tried goggle only to get more confused. please is there an easier guide out there that i can follow step by step understandably?
Below is the full code in the book;
def hangman():
word= "caat"
wrong_guesses =0
stages=["","_______ ","| | ","| 0 ","| /| ","| / ","| "]
letters_left= list(word)
score_board= ['_']*len(word)
win= false
print('Welcome to Hang man')
while wrong_guesses<len(stages)-1:
print('n')
guess=input("Guess a letter")
if guess in letters_left:
character_index=letters_left.index(guess)
score_board[character_index]=guess
letters_left[character_index]='$'
else:
wrong_guesses+=1
print(''.join(score_board))
print('n'.join(stages[0:wrong_guesses+1]))
if'_'not in score_board:
print('You win!The word was:')
print(''.join(score_board))
win= True
break
if not win:
print('n'.join(wrong_guesses[0:stage]))
print('You lose! The words was{}'.formed(word))
hangman()
def hangman():
stage=()
wrong_guesses=["","____","|| ","| () ","| /| ","| / ","| "]
word='cat'
score_board=['_']*len(word)
win=False
print('Welcome to Hangman')
while stage<len(wrong_guesses)-1:
print('n')
guess=input("Guess a letter")
if guess in word:
score_board[word.index(guess)]=guess
else:
stage+=1
print((''.join(score_board)))
print('n'.join(wrong_guesses[0:stage+1]))
if '_'not in score_board:
print('You win! The word was:')
print(''>join(score_board))
win=True
if not win:
print('n'.join(wrong_guesses[0:stage]))
print('You lose')
hangman()
1