SHARE
TWEET

Untitled

a guest Aug 14th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import random
  2.  
  3. def letter_count():
  4.     current_word = []
  5.     if fails > 0:
  6.         for letter in word:
  7.             if letter in guessed:
  8.                 current_word.append(letter)
  9.             else:
  10.                 current_word.append("_")
  11.     else:
  12.         for letter in word:
  13.             current_word.append("_")
  14.     return current_word
  15.  
  16. # A list of words that
  17. potential_words = ["example", "words", "someone", "can", "guess"]
  18.  
  19. word = random.choice(potential_words)
  20.  
  21. # Use to test your code:
  22. # print(word)
  23.  
  24. # Converts the word to lowercase
  25. word = word.lower()
  26.  
  27. fails = 0
  28. # Make it a list of letters for someone to guess
  29.  
  30. letter_count()
  31.  
  32. # Some useful variables
  33. guessed = []
  34. maxfails = 7
  35. fails = 0
  36.  
  37. while fails < maxfails:
  38.  
  39.     print(*letter_count())
  40.  
  41.     check = False
  42.     while check == False:
  43.         guess = input("Guess a letter: ")
  44.  
  45.         if guess.isalpha():
  46.             check = True
  47.         else:
  48.             print("That isn't a letter.")
  49.  
  50.         guessed.append(guess)
  51.  
  52.     if guess in word:
  53.         letter_count()
  54.     else:
  55.         fails += 1
  56.  
  57.  
  58.     print("You have " + str(maxfails - fails) + " tries left!")
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