-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWordle.py
112 lines (105 loc) · 3.36 KB
/
Wordle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#Attempt to create a wordle game
import random
import string
#test function
def test(word, guess, alpha,arr, tempList):
for i in range(5):
char1, char2 = word[i], guess[i]
print(char2, "-", sep = "", end = "")
#correct letter, correct position
if char1 == char2:
print("🟩")
if char2 not in tempList:
tempList.append(char2)
arr[i] = char2
#letter absent
elif char2 not in word:
print("⬛")
try:
alpha.remove(char2)
except ValueError:
pass
#letter present in word
else:
#counting no. of times letter present
w_cnt = 0
for elem in word:
if elem == char2:
w_cnt += 1
#counting no. of times letter present in guess previously
g_cnt = 0
for elem in guess[:i]:
if elem == char2:
g_cnt += 1
if w_cnt - g_cnt > 0:
print("🟨")
else:
print("⬛")
#letter in our tempList
if char2 not in tempList:
tempList.append(char2)
#Printing correct letters
print("Correct letters-", tempList)
#Printing the progress
print("Progress-",arr)
#Printing available letters
print("Available letters-", end = " ")
for char in alpha:
print(char, end = "")
print()
#Starting the game
def wordle(word):
#List of all alphabets
alphabet_string = string.ascii_uppercase
alpha_list = list(alphabet_string)
#List displaying correct positions
arr = ["_","_","_","_","_"]
tempList = []
#6 guesses from user
count = 6
i = 1
while(i <= 6):
print("Guesses Left:", count)
if i == 1:
guess = input("Please Enter Your Guess: ")
else:
guess = input("Please Enter Your Next Guess: ")
if len(guess) != 5:
print("Please enter a valid 5 letter word.")
i -= 1
continue
guess = guess.upper()
#insert a check function here
test(word, guess, alpha_list,arr,tempList)
count -= 1
if word == guess:
print()
print("*****************************************")
print("Hurray!!")
print("The Word Was " , word, "!", sep = "")
print("You Have Solved The Wordle!!")
print("*****************************************")
return
i+=1
print("*****************************************")
print("The Word Was ", word, "!", sep = "")
print("Better Luck Next Time.")
print("*****************************************")
return
if __name__ == '__main__':
#alphabet_string = string.ascii_lowercase
alphabet_string = string.ascii_lowercase
alphabet_string = alphabet_string.upper()
f = open("Modern word list.txt", "r")
#All valid 5 letter words
wordList = []
for elem in f:
elem = elem.upper()
wordList.append(elem[:5])
#Word of the round
word = random.choice(wordList)
print("*****************************************")
print("Welcome!")
print("*****************************************")
wordle(word)
f.close()