Guest User

Untitled

a guest
Jan 21st, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. import random
  2. def GAME():
  3. win = 0
  4. guessedletters = []
  5. display = []
  6. alphabet = 'abcdefghijklmnopqrstuvwxyz'
  7. f = open('hang.txt','r')
  8. lines = f.readlines()
  9. rand = random.randrange(0,51,2)
  10. rand = lines[rand]
  11. for ii in rand:
  12. display.append('_')
  13. rand = list(rand)
  14. rand.remove('n')
  15. chances = 9
  16. while chances > 0:
  17. if '_' not in display:
  18. print('Congratulations! You guessed the word!')
  19. win = 1
  20. break
  21. print(display)
  22. print(chances,'guesses left.')
  23. guess = input('Guess a letter: ')
  24. if guess not in alphabet:
  25. print('Not a letter')
  26. continue
  27. elif guess in guessedletters:
  28. print('Already guessed')
  29. continue
  30. else:
  31. guessedletters.append(guess)
  32. chances -= 1
  33. if guess in rand:
  34. print(guess,'is in the word!')
  35. q = rand.index(guess)
  36. del display[q]
  37. display.insert(q, guess)
  38. else:
  39. print('Not in the word!')
  40. continue
  41. if win != 1:
  42. print('The word was',rand,'.')
  43. print('Thanks for playing!')
  44. again = input('Press enter to play again, and N to quit.')
  45. if again == '':
  46. return GAME()
  47. else:
  48. return print('Goodbye!')
  49. GAME()
Add Comment
Please, Sign In to add comment