Created
January 8, 2016 06:46
-
-
Save codeboy101/359a5f0546825c6ede81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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