Python - Wordle Game
- Lucy Tsai
- Mar 5, 2022
- 1 min read
Updated: Sep 9, 2023
Made my own Wordle game with Python.
Code:
from colorama import Fore
# set name
words = []
word = "catch"
mychoice = "_____"
rightwords = 0
finalword = ""
chance = 1
# Functions
def chooseWord():
global mychoice, rightwords, finalword, chance
finalword = ""
if chance >= 6:
print("Out of Chances")
quit()
print(Fore.LIGHTGREEN_EX + "Chance ", chance)
chance += 1
mychoice = input(Fore.LIGHTWHITE_EX + "Five letter: ")
rightwords = 0
if len(mychoice) != 5:
print("not 5 words")
chooseWord()
else:
checkWord()
def checkWord():
global mychoice, rightwords, finalword
for i in range(5):
if mychoice[i] == word[i]:
rightwords += 1
if rightwords >= 5:
print(Fore.LIGHTYELLOW_EX + "All pass")
quit()
# check right words
for i in range(5):
# individual right
if mychoice[i] == word[i]:
#print("the ", i + 1, " is correct")
# correct space
finalword += Fore.LIGHTYELLOW_EX + mychoice[i]
elif mychoice[i] in word:
# wrong space
finalword += Fore.WHITE + mychoice[i]
else:
# doesn't exist
finalword += Fore.LIGHTGREEN_EX + mychoice[i]
print(finalword)
if rightwords < 5:
chooseWord()
# Main
print(Fore.LIGHTBLUE_EX + """
Rules:
Guess a five lettered word.
Yellow - correct space
Grey - right word, but wrong space
Green - not in the word
You have 6 chances.
""")
chooseWord()Console:

Comments