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 time | |
import random | |
name = input("What is your name? ") | |
print ("Hello, " + name, "Time to play hangman!") | |
time.sleep(1) | |
print ("Start guessing...\n") | |
time.sleep(0.5) | |
## A List Of Secret Words | |
words = ['python','programming','treasure','creative','medium','horror'] | |
word = random.choice(words) | |
guesses = '' | |
turns = 5 | |
while turns > 0: | |
failed = 0 | |
for char in word: | |
if char in guesses: | |
print (char,end="") | |
else: | |
print ("_",end=""), | |
failed += 1 | |
if failed == 0: | |
print ("\nYou won") | |
break | |
guess = input("\nguess a character:") | |
guesses += guess | |
if guess not in word: | |
turns -= 1 | |
print("\nWrong") | |
print("\nYou have", + turns, 'more guesses') | |
if turns == 0: | |
print ("\nYou Lose") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment