Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import words
- random_word = words.get_words()
- print(random_word)
- input("Welcome to ===HANGMAN===" " " "Please press enter to start the game")
- print()
- #using three variables to control the game. a will open/close the loop,b is for how many numbers guessed right, and d is
- #controlling wether the guess is right/wrong. N=number of attempts
- a = 0
- b = 0
- N = 10
- length = (len(random_word))
- secret_word = ("_" * length)
- print(secret_word)
- while a == 0:
- d = 1
- e = input ("\n guess a letter in the word(only one letter)")
- found = False
- for i in range(length):
- if random_word[i] == e:
- secret_word = secret_word[0:i] + random_word[i] + secret_word[i+1:len(secret_word)]
- d = 0
- b = b+1
- found = True
- if found == True:
- print ("you found a letter\n")
- if d == 1:
- print("that was wrong")
- print()
- N = N -1
- print("attempts left:")
- print(N)
- print()
- print(secret_word)
- if N == 0:
- print("you lost")
- a = 1
- print("the word is: "+ random_word)
- if b == length:
- a = 1
- print("congratulations, you won!")
- print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement