Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def letter_count():
- current_word = []
- if fails > 0:
- for letter in word:
- if letter in guessed:
- current_word.append(letter)
- else:
- current_word.append("_")
- else:
- for letter in word:
- current_word.append("_")
- return current_word
- # A list of words that
- potential_words = ["example", "words", "someone", "can", "guess"]
- word = random.choice(potential_words)
- # Use to test your code:
- # print(word)
- # Converts the word to lowercase
- word = word.lower()
- fails = 0
- # Make it a list of letters for someone to guess
- letter_count()
- # Some useful variables
- guessed = []
- maxfails = 7
- fails = 0
- while fails < maxfails:
- print(*letter_count())
- check = False
- while check == False:
- guess = input("Guess a letter: ")
- if guess.isalpha():
- check = True
- else:
- print("That isn't a letter.")
- guessed.append(guess)
- if guess in word:
- letter_count()
- else:
- fails += 1
- print("You have " + str(maxfails - fails) + " tries left!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement