Untitled

 avatar
unknown
plain_text
a year ago
2.0 kB
5
Indexable
#import English dictionary
import nltk
nltk.download('words')
from nltk.corpus import words

print("Weclome 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()
    while (len(player_word) != 5):
        letter_word = int(len(player_word))
        print(f'You entered a {letter_word}-letter word, but a 5-letter word is needed. Try again')
        player_word = input((f"Enter you attempt #{attempts}\n"))
        
    if (len(player_word) == 5 and player_word in words.words()):
        letter_in_the_right_spot = 0
        print('You entered a 5-letter word')

        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 word guess is correct
        if letter_in_the_right_spot == 5:
            print("Congrats you won using", attempts, "attempt(s)")
            break
        elif attempts == N:
            print(f"You already used #{N} attempts. Better luck tomorrow!")
            break
        attempts += 1

Editor is loading...