Skip to content

Instantly share code, notes, and snippets.

@codeboy101
Created January 8, 2016 06:46
Show Gist options
  • Save codeboy101/359a5f0546825c6ede81 to your computer and use it in GitHub Desktop.
Save codeboy101/359a5f0546825c6ede81 to your computer and use it in GitHub Desktop.
import random
namePeople = ['birthday' , 'airplane' , 'tiger' , 'butterfly' , 'giraffe']
wordGenerated = (random.choice(namePeople))
times_failed = 0
while True :
userGuess = input("Guess the word: ")
if userGuess == wordGenerated :
print("You got it right!")
break #break escapes the loop and goes to line 20
else :
if times_failed < len(wordGenerated): ## magic happens here
output = wordGenerated[0:times_failed] + (len(wordGenerated)-times_failed) * "*"
print(output)
else:
print(wordGenerated)
times_failed += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment