New answers tagged

2

I would turn around the logic. The design you have has a lot of the general logic in the main program, and a lot of game-specific logic in the questions module. A better design for reusability would be to put the logic in a module, and the game-specific stuff (basically just the questions and perhaps some very superficial user interface) in the main program. ...


6

Very fun game you created here, I like it. Your calculations for the probabilities are also impressive, and well tested. Some small suggestions: UI improvement: Print a message when "leveling up". Answer.Wrong.also { } has a redundant .also that can be removed. Enum constants are usually written in uppercase, making it AND, OR, XOR, IMPLIES. The usage of ...


2

What stands out to me is the use of when in BinOp instead of object oriented patterns. The eval and probabilities methods could be replaced with lambda properties and/or by overriding abstract methods. For example: enum class BinOp(val sym: String, val eval: (Boolean, Boolean) -> Boolean) { // For the eval property use a lambda And("and", { a, b ...


10

1. Instead of: def __init__(self, root): """Constructor""" self.root = root # root is a passed Tk object do: def __init__(self, root: tkinter.Tk) -> None: self.root = root Python 3 has built in support for type annotations, so there's no reason to use comments to say what the type of a variable is. If you use mypy (and if you're writing ...


4

If talking about code readability, I'd recommend you to read PEP-8 at first, for example: def one(): pass def two(): pass This is how you don't want your code to look like. Instead, it should look like this: def one(): # you can add hints for this function here pass def two(): ''' or if it's documentation, you can leave it here '''...


Top 50 recent answers are included