used characters
This commit is contained in:
parent
7fc74c8e1f
commit
f8c8637dfa
13
wordle.py
13
wordle.py
|
@ -1,3 +1,5 @@
|
|||
#!/bin/env python
|
||||
|
||||
import random
|
||||
|
||||
def getw():
|
||||
|
@ -12,16 +14,20 @@ def getw():
|
|||
return palabra
|
||||
|
||||
def word(palabra):
|
||||
used_char = []
|
||||
hp = 5
|
||||
while hp != 0:
|
||||
print('Enter a 5-letter word: ')
|
||||
guess = input()
|
||||
print('\n')
|
||||
guess = guess.lower()
|
||||
if len(guess) != 5:
|
||||
print('That word has ' + str(len(guess)) + ' letters instead of 5!\n')
|
||||
continue
|
||||
else:
|
||||
for x in guess:
|
||||
if x not in used_char:
|
||||
used_char.append(x)
|
||||
if x not in palabra:
|
||||
guess = guess.replace(x, '_')
|
||||
i = 0
|
||||
|
@ -30,10 +36,15 @@ def word(palabra):
|
|||
break
|
||||
while i != 5:
|
||||
if guess[i] == palabra[i]:
|
||||
guess = guess.replace(guess[i], guess[i].upper())
|
||||
guess = guess[:i] + guess[i].upper() + guess[i+1:]
|
||||
i += 1
|
||||
print(guess)
|
||||
hp -= 1
|
||||
msg = '\nUsed characters: ' + str(used_char) + '\n'
|
||||
msg = msg.replace('[', '')
|
||||
msg = msg.replace(']', '')
|
||||
msg = msg.replace("'", '')
|
||||
print(msg)
|
||||
if hp == 0:
|
||||
print('u lost! the word was ' + palabra + ' :(')
|
||||
hint = '_ _ _ _ _'
|
||||
|
|
Loading…
Reference in New Issue