Advertisement
Enrro

Hangman 110633

Nov 6th, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. '''
  2. Created on 06/11/2014
  3. Hangman
  4. Proven and tested on python 3.3.3
  5. @author: A01221672
  6. '''
  7. import random
  8. foo = ["duck","reddit", "dad", "magic", "frog", "sheep", "injured", "undertaker", "potatoe", "king", "north", "princess", "careful", "hammer", "shaman", "gorilla"]
  9. li0 = []
  10. bar = []
  11. hp1 = 7
  12. ho1 = random.choice(foo)
  13. qu1 = ""
  14. ca1 = 0
  15.  
  16. '''
  17. with open("words.txt") as file:
  18. for line in file:
  19. li0.append(str(line.strip()))
  20. ho2 = random.choice(li0)
  21. '''
  22. #print(ho1)
  23. #random of a list returns an integer
  24. #len of an integer returns an integer with the amount of characters
  25.  
  26. for x in range(len(ho1)):
  27. bar.append("_")
  28.  
  29. #create a list with the amount of elements the word you are looking for has
  30. print("Welcome to the hangman game. You have 7 lives use them wisely.")
  31. print(bar)
  32. while True:
  33. qu1 = input("Guess a letter of the word: ")
  34. for i in range(len(ho1)):
  35. if ho1[i] == qu1:
  36. bar[i] = qu1
  37. ca1 = ca1 + 1
  38. if ca1 == 0:
  39. hp1 = hp1 - 1
  40. print("That is not a correct answer.")
  41. print(str(hp1) + " lives left.")
  42. print(bar)
  43. ca1 = 0
  44. if hp1 <= 0:
  45. break
  46.  
  47. print("End of the game")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement