Another program. This one has you guess 5 letters and then gives you the word you're trying to guess as masked by -'s and has the letters you've guessed filled in.
Ex:
Say the word is "computer." If you guess "r," "s," "e," "a," and "m." It would say:
--m--er
Guess the word:
# import module for random functions
import random
# List of words for the computer to pick from
words = ("basketball", "football", "hockey", "lacrosse", "baseball")
# Word to be guessed; picked at random
word = random.choice(words)
letters_guessed = []
print "Guess the sport!"
print "You get to give five letters."
print "There are %s letters in the word." % (len(word))
guesses = 5
while guesses != 0:
letter = raw_input("Enter a letter: ")
if letter in letters_guessed:
print "You already guessed that letter."
else:
guesses = guesses - 1
print "You have %d guesses left." % (guesses)
letters_guessed.append(letter)
print "The word:"
masked_word = ""
for letter in word:
if letter in letters_guessed:
masked_word += letter
else: masked_word += "-"
print masked_word
guess = raw_input("Guess the word: ")
if guess == word:
print "Congratulations, %s is the word!" % (guess)
else:
print "Nope. The word is %s." % (word)
Once again, could you good python programmers check out my program and see how it could be more efficient, more user-friendly, or changed. All of my programs are for learning purposes. Thanks for your help.