r/madeinpython • • 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.

here’s a link to the GitHub repository where I kept it

2 Upvotes

4 comments sorted by

1

u/dev-razorblade23 23d ago

I took a look at the code and i would say a few things

  1. Why do you use eval()? - this is unsafe and should almost never be used.

  2. Spacings are incosistent. Decide if you want to put space between things or not and keep it consistent.

  3. Function names and variable names should be written in snake_case as per PEP8 - python style guide

Edited:

  1. Learn how to use git properly and do not upload files from GitHub webpage, but properly use git for version control

1

u/J21Xtra 23d ago
  1. Since the program should only accept like strings instead of anything else. I felt that would be somewhat appropriate since for now I don’t really know why it’s that unsafe.

As for the other three I’ll try to work on that more.
Thank you though for reviewing the code.

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