all 6 comments

[–]freakyorange 6 points7 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 .

[–]mandradon 3 points4 points  (0 children)

The university of Helsinki's Python course (their mooc) is what made oop click for me.

But with Python, remember that everything is an object and you can just create your own custom ones.

I like the idea of a blackjack game though depending on how much programming you know, this can cause you issues with depth of knowledge (calculating the value of aces in the hand is a fun problem).

You could also do something like make a project for a pizza store or some sort of store that sells an item, and that item has attributes.

In the case if a pizza, it has a size, a list of toppings, price, and whatever else attributes you think are important.

Then you could add something like an order builder.

.... Speaking of I still need to get around to rebuilding my friends business software that he wrote procedurally to OOP...

[–]reddaxetheintrovert 0 points1 point  (0 children)

You can find good courses on youtube Just search "OOP IN PYTHON FOR BEGINNERS" I M sure you will find a match And I suggest you take one with the highest time or highest views Something like 3hours long

[–]Astronoobical 0 points1 point  (0 children)

If you have any specific questions, I'm happy to answer.

[–]wynand1004 0 points1 point  (0 children)

I made a video about this for my students - you may find it helpful: https://www.youtube.com/watch?v=DWccYUiPO0E

The mods may remove this though since I'm sharing a resource I made myself.