Skip to content

Commit e02ac5e

Browse files
committed
Update wordle.py
1 parent efdfee0 commit e02ac5e

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

Wordle/wordle.py

+4-17
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@
2626
import random
2727

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

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

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

10598

10699
answer_given = False
107100
do_not_add = False
108101
# Check if letter is in word
109102
if user_inp[letter] in word:
110-
# Set answer_given to true
111103
answer_given = True
112104
# Check if letter is in the correct position
113105
if user_inp[letter] == i:
114-
# Set return answer to G
115106
return_answer += "G"
116107
else:
117108
if not user_inp[word.index(user_inp[letter])] == word[word.index(user_inp[letter])]:
118-
# Set return answer to Y
119109
return_answer += "Y"
120110
else:
121111
answer_given = False
122112
do_not_add = True
123113

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

129118
# Append checked letter to the list letters_checked
130119
if not do_not_add:
131120
letters_checked.append(user_inp[letter])
132-
# Increase letters by 1
121+
133122
letter += 1
134123

135-
# Print the return answer
136124
print(return_answer)
137125

138-
# Increase tries by 1
139126
tries += 1

0 commit comments

Comments
 (0)