|
26 | 26 | import random
|
27 | 27 |
|
28 | 28 | # 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 |
34 | 32 |
|
35 | 33 | # Choose a random word from the dictionary
|
36 | 34 | word = random.choice(dictionary)
|
|
88 | 86 | counter += 1
|
89 | 87 | # Check if letter has been checkd more or equal to the ammount of these letters inside of the word
|
90 | 88 | if counter >= count_letters[i]:
|
91 |
| - # If so set cont to true |
92 | 89 | cont = True
|
93 | 90 |
|
94 | 91 | # Check if cont is true
|
95 | 92 | if cont:
|
96 |
| - # Set return answer to - |
97 | 93 | return_answer += "-"
|
98 |
| - # Append checked letter to the list letters_checked |
99 | 94 | letters_checked.append(user_inp[letter])
|
100 |
| - # Increase letters by 1 |
101 | 95 | letter += 1
|
102 |
| - # Go back to the beginning of the for loop (skipping everything that comes after this) |
103 | 96 | continue
|
104 | 97 |
|
105 | 98 |
|
106 | 99 | answer_given = False
|
107 | 100 | do_not_add = False
|
108 | 101 | # Check if letter is in word
|
109 | 102 | if user_inp[letter] in word:
|
110 |
| - # Set answer_given to true |
111 | 103 | answer_given = True
|
112 | 104 | # Check if letter is in the correct position
|
113 | 105 | if user_inp[letter] == i:
|
114 |
| - # Set return answer to G |
115 | 106 | return_answer += "G"
|
116 | 107 | else:
|
117 | 108 | if not user_inp[word.index(user_inp[letter])] == word[word.index(user_inp[letter])]:
|
118 |
| - # Set return answer to Y |
119 | 109 | return_answer += "Y"
|
120 | 110 | else:
|
121 | 111 | answer_given = False
|
122 | 112 | do_not_add = True
|
123 | 113 |
|
124 | 114 | # Check if there has already been an answer returned
|
125 | 115 | if not answer_given:
|
126 |
| - # Set return answer to - |
127 | 116 | return_answer += "-"
|
128 | 117 |
|
129 | 118 | # Append checked letter to the list letters_checked
|
130 | 119 | if not do_not_add:
|
131 | 120 | letters_checked.append(user_inp[letter])
|
132 |
| - # Increase letters by 1 |
| 121 | + |
133 | 122 | letter += 1
|
134 | 123 |
|
135 |
| - # Print the return answer |
136 | 124 | print(return_answer)
|
137 | 125 |
|
138 |
| - # Increase tries by 1 |
139 | 126 | tries += 1
|
0 commit comments