Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. # hangman
  2.  
  3. #import random number function
  4. import random
  5.  
  6. #import time function
  7. import time
  8.  
  9. #prints to user
  10. print "Welcome to hangman!\n"
  11.  
  12. time.sleep(0.5)
  13.  
  14. print "Start guessing...\n"
  15.  
  16. time.sleep(0.5)
  17.  
  18. #word generator
  19. def word_gen(min_length=5, filename="words.txt"):
  20.     min_line_length = min_length + 1
  21.     with open(filename) as wordlist:
  22.         words = [line for line in wordlist if len(line) >= min_line_length]
  23.     word = random.choice(words).lower
  24.  
  25.     print word
  26.    
  27. #number of guesses
  28. guesses = 0
  29.  
  30. #number of turns
  31. turns = 10
  32.  
  33. while turns > 0:
  34.     for char in word:
  35.         print char
  36.        
  37.  
  38. print "------------\n|          |\n|\n|\n|\n|\n|\n|\n|\n|\n------------\n|          |\n------------\n"
  39.  
  40. word_gen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement