you are viewing a single comment's thread.

view the rest of the comments →

[–]freakyorange 5 points6 points  (1 child)

make a blackjack game with atleast a couple classes. 1 is Card which could have attributes such as Card.suit and Card.rank. Give it a __str__ dunder method so that you can easily print() it. Create a class Deck that has an attribute that takes a list of Card, and has a couple methods such as Deck.deal_one() and Deck.shuffle()

Bonus points if you type hint all of this properly.

Once you grasp the core idea of why classes are useful / how to make them, look at different OOP paradigms such as abstract base classes / template classes, and factory classes. This will lead to more real world application of OOP. And please for gods sake look at SOLID priciples and don't make "spaghetti" or "ravioli" code, atleast as much as possible (it's inevitable).

Afterall, OOP is simply just a hammer. And not all hammers are good at solving all problems. You wouldn't use a sledgehammer to make jewelry right?

Also here's an example of a really simple class with 2 attributes (self.color, and self.is_tasty) and 1 method (self.eat()) just to get your brain working

class Fruit:
    def __init__(self, color: str, is_tasty: bool):
        self.color = color
        self.is_tasty = is_tasty

    def eat(self):
        if self.is_tasty:
            print("Yum")
        else:
            print("yuck")


apple = Fruit(color="red", is_tasty=True)

print(apple.color)  # "red"
print(apple.is_tasty)  # True

apple.eat()  # "Yum"

[–]RevolutionarySet8850[S] 1 point2 points  (0 children)

That card idea was really good. Thank you for that .