Untitled
unknown
plain_text
2 years ago
1.9 kB
7
Indexable
#import English dictionary
import nltk
nltk.download('words')
from nltk.corpus import words
print("Welcome to Wordle - CECS 174 edition!")
#Taking out secret word
while True:
secret_word = input("Enter the secret 5-letter word: ").lower()
# Check if the word is a valid English word
if secret_word in words.words():
is_word = True
else:
is_word = False
#Check if input secret word is valid
if (is_word == True and len(secret_word) == 5):
break
print("Not a valid word, try again!")
N = int(input("Input allowed number of attempts: "))
attempts = 1
while attempts <= N:
#Take input of player word
player_word = input((f"Enter you attempt #{attempts}\n")).lower()
if (len(player_word) == 5 and player_word in words.words()):
letter_in_the_right_spot = 0
print('You entered a 5-letter word')
#Checks if letter in secret_word and letter_word match
for i in range(5):
for j in range(5):
if secret_word[i] == player_word[j]:
if i == j:
print(f"{player_word[j]} is in the secret_word and in the correct spot #{j + 1}")
letter_in_the_right_spot += 1
print("Correct letters in the correct spot:", letter_in_the_right_spot)
else:
print(player_word[j], "is in the secret_word but not in the correct spot")
#Check if guessed player_word is correct
if letter_in_the_right_spot == 5:
print("Congrats you won using", attempts, "attempt(s)")
break
#If attempts is used up end the program
if attempts == N:
print(f"You already used #{N} attempts. Better luck tomorrow!")
attempts += 1
#If player_word is not of length 5 and is not a valid word
else:
print("Not a valid word, try again")
Editor is loading...