Skip to content

Commit

Permalink
Update wordle.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Cerabbite committed Mar 11, 2022
1 parent efdfee0 commit e02ac5e
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions Wordle/wordle.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@
import random

# Load 5 letter word dictionary
dictionary = open("5 letter word dictionary.txt", 'r')
# Read content of dictionary
dictionary = dictionary.read()
# Split the dictionary on every new line
dictionary = dictionary.split('\n') # This returns a list of all the words in the dictionary
with open("5 letter word dictionary.txt", 'r') as dictionary:
# Read content of dictionary
dictionary = dictionary.read().split('\n') # This returns a list of all the words in the dictionary

# Choose a random word from the dictionary
word = random.choice(dictionary)
Expand Down Expand Up @@ -88,52 +86,41 @@
counter += 1
# Check if letter has been checkd more or equal to the ammount of these letters inside of the word
if counter >= count_letters[i]:
# If so set cont to true
cont = True

# Check if cont is true
if cont:
# Set return answer to -
return_answer += "-"
# Append checked letter to the list letters_checked
letters_checked.append(user_inp[letter])
# Increase letters by 1
letter += 1
# Go back to the beginning of the for loop (skipping everything that comes after this)
continue


answer_given = False
do_not_add = False
# Check if letter is in word
if user_inp[letter] in word:
# Set answer_given to true
answer_given = True
# Check if letter is in the correct position
if user_inp[letter] == i:
# Set return answer to G
return_answer += "G"
else:
if not user_inp[word.index(user_inp[letter])] == word[word.index(user_inp[letter])]:
# Set return answer to Y
return_answer += "Y"
else:
answer_given = False
do_not_add = True

# Check if there has already been an answer returned
if not answer_given:
# Set return answer to -
return_answer += "-"

# Append checked letter to the list letters_checked
if not do_not_add:
letters_checked.append(user_inp[letter])
# Increase letters by 1

letter += 1

# Print the return answer
print(return_answer)

# Increase tries by 1
tries += 1

0 comments on commit e02ac5e

Please sign in to comment.