SHARE
TWEET

Hangman 2

a guest Sep 21st, 2019 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import words
  2. random_word = words.get_words()
  3. print(random_word)
  4.  
  5. input("Welcome to ===HANGMAN===" " " "Please press enter to start the game")
  6. print()
  7.  
  8. #using three variables to control the game. a will open/close the loop,b is for how many numbers guessed right, and d is
  9. #controlling wether the guess is right/wrong. N=number of attempts
  10.  
  11. a = 0
  12. b = 0
  13. N = 10
  14. length = (len(random_word))
  15. secret_word = ("_" * length)
  16. print(secret_word)
  17.  
  18. while a == 0:
  19.     d = 1
  20.     e = input ("\n guess a letter in the word(only one letter)")
  21.     found = False
  22.     for i in range(length):
  23.         if random_word[i] == e:
  24.             secret_word = secret_word[0:i] + random_word[i] + secret_word[i+1:len(secret_word)]
  25.             d = 0
  26.             b = b+1
  27.             found = True
  28.     if found == True:
  29.         print ("you found a letter\n")
  30.  
  31.     if d == 1:
  32.         print("that was wrong")
  33.         print()
  34.         N = N -1
  35.         print("attempts left:")
  36.         print(N)
  37.         print()
  38.  
  39.     print(secret_word)
  40.    
  41.     if N == 0:
  42.         print("you lost")
  43.         a = 1
  44.         print("the word is: "+ random_word)
  45.     if b == length:
  46.         a = 1
  47.         print("congratulations, you won!")
  48.         print()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top