1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
words = ["HELLO", "COMPUTER", "KEYBOARD", "INTERNET", "CORRECT", "HORSE", "BATTERY", "STAPLE"]
word = choice(words)
user = ["_" for _ in word]
tries = 10
while True:
if tries <= 0:
print("You lose!")
print("The word was: " + word)
break
print(" ".join(user))
if user == list(word):
print("You win!")
break
print("%d tries remaining" % tries)
current = input("? ")[:1].upper()
if not current:
continue
for i in range(len(user)):
if word[i] == current:
user[i] = current
if current not in word:
tries -= 1
print("\n")
|