2022-02-05 14:51:35 +00:00
|
|
|
#!/bin/env python
|
|
|
|
|
2022-01-30 00:17:59 +00:00
|
|
|
import random
|
|
|
|
|
|
|
|
def getw():
|
|
|
|
number = random.randrange(8915)
|
|
|
|
f = open("wordle.txt", "r")
|
|
|
|
|
|
|
|
lines = f.readlines()
|
|
|
|
|
|
|
|
palabra = lines[number][0:5]
|
|
|
|
|
|
|
|
f.close()
|
|
|
|
return palabra
|
|
|
|
|
|
|
|
def word(palabra):
|
2022-02-05 14:51:35 +00:00
|
|
|
used_char = []
|
2022-01-30 00:17:59 +00:00
|
|
|
hp = 5
|
|
|
|
while hp != 0:
|
|
|
|
print('Enter a 5-letter word: ')
|
|
|
|
guess = input()
|
2022-02-05 14:51:35 +00:00
|
|
|
print('\n')
|
2022-01-30 00:17:59 +00:00
|
|
|
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:
|
2022-02-05 14:51:35 +00:00
|
|
|
if x not in used_char:
|
|
|
|
used_char.append(x)
|
2022-01-30 00:17:59 +00:00
|
|
|
if x not in palabra:
|
|
|
|
guess = guess.replace(x, '_')
|
|
|
|
i = 0
|
|
|
|
if guess == palabra:
|
|
|
|
print('\nU won!\n\n')
|
|
|
|
break
|
|
|
|
while i != 5:
|
|
|
|
if guess[i] == palabra[i]:
|
2022-02-05 14:51:35 +00:00
|
|
|
guess = guess[:i] + guess[i].upper() + guess[i+1:]
|
2022-01-30 00:17:59 +00:00
|
|
|
i += 1
|
|
|
|
print(guess)
|
|
|
|
hp -= 1
|
2022-02-05 14:51:35 +00:00
|
|
|
msg = '\nUsed characters: ' + str(used_char) + '\n'
|
|
|
|
msg = msg.replace('[', '')
|
|
|
|
msg = msg.replace(']', '')
|
|
|
|
msg = msg.replace("'", '')
|
|
|
|
print(msg)
|
2022-01-30 00:17:59 +00:00
|
|
|
if hp == 0:
|
|
|
|
print('u lost! the word was ' + palabra + ' :(')
|
|
|
|
hint = '_ _ _ _ _'
|
|
|
|
print('\n' + hint + '\n\n')
|
|
|
|
|
|
|
|
palabra = getw()
|
|
|
|
word(palabra)
|