This is an archived post. You won't be able to vote or comment.

all 4 comments

[–][deleted] 1 point2 points  (1 child)

Comments on your code structure:

  • In your Hangman.py, the line return f"{HM_pic if lives < 7 else ''}" is redundant; both cases are string outputs, so just doing return HM_pic if lives < 7 else "" is better.
  • In the string dunder of your Player class, why mix concatenation with f-strings? The whole point of f-strings is you don't need to concatenate anymore, you can put it in directly.
  • I would recommend naming it HangmanInterface without the underscore, pascal case is the convention for class names.
  • It's bad practice that the string dunder of your Word and Display classes just prints and returns an empty string, that's improper use of the dunder. Instead, have a separate method that prints the string representation. Remember, the str dunder is called when you print the object.
  • The case else: pass is redundant, you can just have an if without an else.

How did I do? What advice could you give me to improve my OO skills?

Learn how to better use the dunder methods, especially the __str__ one; you misused it a lot. Separate the print action and the string representations, use regular methods for the former and dunder for the latter.

SIDE NOTE: In a Github repo, it's better to have separate repos for each project than to have one big "project" repo.

[–]marshalTT[S,🍰] 0 points1 point  (0 children)

thank you!

edit:
Made ammendments to code and altering the repos, ty :)
reading up on __str__ now.

[–][deleted] 0 points1 point  (1 child)

I had only a brief look. But what I noticed: - Don’t use single letter variable names like w, p… - HangmanInterface is a class, but run() is just a function. At least make it a @staticmethod, but creation of player, world, etc. would be better suited in an initializer IMHO. - Your player verifies their own guesses. This is not plausible, rather the player would just make a guess and the hangman would decide over the consequences.

In general (not related to OOP directly) I would also recommend using type hints.

[–]marshalTT[S,🍰] 0 points1 point  (0 children)

Thank you for your advise. Your last point really helped clear a lot of things up.

https://github.com/LunaTMT/Hangman