Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def GAME():
- win = 0
- guessedletters = []
- display = []
- alphabet = 'abcdefghijklmnopqrstuvwxyz'
- f = open('hang.txt','r')
- lines = f.readlines()
- rand = random.randrange(0,51,2)
- rand = lines[rand]
- for ii in rand:
- display.append('_')
- rand = list(rand)
- rand.remove('n')
- chances = 9
- while chances > 0:
- if '_' not in display:
- print('Congratulations! You guessed the word!')
- win = 1
- break
- print(display)
- print(chances,'guesses left.')
- guess = input('Guess a letter: ')
- if guess not in alphabet:
- print('Not a letter')
- continue
- elif guess in guessedletters:
- print('Already guessed')
- continue
- else:
- guessedletters.append(guess)
- chances -= 1
- if guess in rand:
- print(guess,'is in the word!')
- q = rand.index(guess)
- del display[q]
- display.insert(q, guess)
- else:
- print('Not in the word!')
- continue
- if win != 1:
- print('The word was',rand,'.')
- print('Thanks for playing!')
- again = input('Press enter to play again, and N to quit.')
- if again == '':
- return GAME()
- else:
- return print('Goodbye!')
- GAME()
Add Comment
Please, Sign In to add comment