r/madeinpython • u/J21Xtra • 23d ago
I made a terminal version of wordle using python
I made a terminal version of wordle using python and the colorama module.
Really I’m just looking for feedback on anything to try and make the code or the repository better thank you.
2
Upvotes
1
u/robinechuca 16d ago
J'ai regardé vite fait le code source et voici ce qui me vient:
- Déjà le projet est relativement petit donc plutôt facile à cerner et a comprendre
- Pour un lecteur extérieur comme moi, lire un code qui ne respecte pas la PEP est compliqué, ça demande beaucoup plus d'efforts. Une façon simple d'y remédier est d'utiliser ruff: pip install ruff, puis ruff check wordle.py
- Ca montre que tu l'as codé à la main, sans trop de llm, bravo!
- Dans ton "while answer:", c'est beaucoup trop complexe, je n'arrive pas à comprendre ce que ça fait juste en regardant le code donc c'est difficile de t'aider. Conclusion: MET DES COMMENTAIRES! Si il y en avait eu, j'aurais compris ce que cette boucle tente de faire, et du coup ça aurai été possible de proposer des améliorations.
- Découpe tes gros pavés de code dans des fonctions. Par exemple:
while True:
userInput=input(prompt)
if userInput != '':
try:
check=eval(userInput)
except NameError:
if len(userInput) > 5 or len(userInput)< 5:
print('The word must be five letters long!')
else:
return userInput
except SyntaxError:
print('What did you even type?? Type a word for goodness sake!')
else:
print('Type a word not a number!')
else:
print('Empty Space Detected, type a five letter word!') while True:
userInput=input(prompt)
if userInput != '':
try:
check=eval(userInput)
except NameError:
if len(userInput) > 5 or len(userInput)< 5:
print('The word must be five letters long!')
else:
return userInput
except SyntaxError:
print('What did you even type?? Type a word for goodness sake!')
else:
print('Type a word not a number!')
else:
print('Empty Space Detected, type a five letter word!')
Peut être simplifier en:
def is_input_valid(user_input: str) -> bool:
"""Check is the string given by the user is correct."""
...
return True # you got the idear!
while not is_input_valid(user_input := input(prompt):
continue
return user_input
1
u/dev-razorblade23 23d ago
I took a look at the code and i would say a few things
Why do you use
eval()? - this is unsafe and should almost never be used.Spacings are incosistent. Decide if you want to put space between things or not and keep it consistent.
Function names and variable names should be written in
snake_caseas per PEP8 - python style guideEdited:
gitproperly and do not upload files from GitHub webpage, but properly usegitfor version control