0

I need help with a function that loops the input turn to the number of lives. For the code below 👇

import random name = ['deafening', 'frequently', 'ancient'] def guess(): word = random.choice(name) count= len(word) lives= len(word)-1 print(str(count) + '*Letters in the word') turn1=input('Enter a letter you think is in the word then press Enter!......?') if turn1 in word: print('correct') print('Positiont' + str(word.index(turn1))) print('Next letter?') else: print('wrong') print('Try again!') print(str(lives) + '*Lives left') guess()

13th Feb 2017, 4:22 AM
Pride Mawire
Pride Mawire - avatar
1 Answer
0
That should get you started. def guess(): word = random.choice(name) count = len(word) lives = len(word) - 1 print(str(count) + '*Letters in the word') while lives > 0: turn1 = input('Enter a letter you think is in the word then press Enter!......? ') if turn1 in word: print('correct') print('Position ' + str(word.index(turn1) + 1)) # Added 1 to position for clarity print('Next letter?') else: print('wrong') print('Try again!') print(str(lives) + '*Lives left') lives -= 1 # subtract 1 when they get it wrong guess() # fixed indenting here so it wasn't part of the else block
13th Feb 2017, 4:47 AM
ChaoticDawg
ChaoticDawg - avatar