Challenge: Modeling a Farm
00:00 So as always, if you don’t practice it, you don’t really understand it. It’s all fine and well to watch slides and nod and say, yeah, yeah, that makes sense. But until you actually have to write it yourself from scratch, things don’t really click. Your challenge is to model a farm.
00:16
You don’t want to let things go ahead of yourself, but you do want to try and use all the tools that you’ve learned so far. So here’s a suggestion. Model four classes, say one Animal
class and then three classes that inherit from Animal
.
00:30
Each class should have a few attributes and at least one method, maybe making sounds, eating, sleeping. Maybe they should be variations for the classes that inherit from the Animal
class. Then try and model two more classes, maybe a Field
, maybe a Barn
.
00:47 Maybe these can even have a parent class.
00:51
Then make these places have an attribute where they can store Animal
objects. So you’re starting to model a farm where you may have cows in one field and then you move them to the barn, and maybe the barn already has some pigs and some horses.
01:06 Maybe you feed the animals with other classes that can represent foods. Maybe each animal has a level of hunger and enjoyment. Get creative with it. But again, don’t get carried away with it.
01:21 But try and put into practice everything you’ve learned in this course so far.
Martin Breuss RP Team on April 20, 2023
@Pythagoras thanks for your feedback! We’ve actually been experimenting with just the format that you’re mentioning in the File Systems Operations course. On the Python Basics Learning Path, you’ll see an associated extra course called Python Basics Exercises: File System Operations.
Let us know how you like the format if you get a chance to take a look, we might roll them out for more courses if our subscribers think that it’s a good idea :)
Katya on May 28, 2023
Hello!
The tutorial was helpful, and the information was explained in a clear way. I agree with @Pythagoras. Having an extra video that shows how you solve the challenge after trying on your own would be super beneficial. That would allow us to see what mistakes were made, if any, and clarify some concepts. I’m surprised none of the tutorials includes that. Is there a way to get a review of the solution?
Thanks, Katya
Bartosz Zaczyński RP Team on May 29, 2023
@Katya Since these courses are based on the Python Basics book, you can find the corresponding exercises and their solutions there. For various reasons, it was decided not to show the solutions in some of the videos. In the meantime, I’d encourage you to share your solution on the Real Python community Slack, asking for feedback or help if you get stuck anywhere. Alternatively, if you have a specific question, then you can post it under the relevant lesson, and we’ll be happy to answer!
Herr Sodrak on Oct. 14, 2023
Definitely agree to aforementioned suggestions of including an “Exercise” section on “some” abstract topics that require more practice with solutions. Thank you for your consideration.
Martin Breuss RP Team on Oct. 15, 2023
@Katya and @Herr Sodrak we’ve heard your feedback and recorded more exercise-solution courses for the whole Python Basics Learning Path 😄
The one that’s associated with this course is currently in post-production and will be published shortly. You’ll then find it embedded right in the learning path.
Exercises courses for the other chapters have either already been published, or are on their way :)
Herr Sodrak on Oct. 15, 2023
Thank you Martin for the update. Cheers!
Martin Breuss RP Team on Oct. 25, 2023
Aaand the exercises course is out now: Python Basics Exercises: Building Systems with Classes. Hope it’s useful :)
Ash D on Dec. 18, 2023
I had a ton of fun modeling this! I highly recommend spending a couple of hours on this, it really does help hammer home the concepts in this course, particularly around the design aspect, figuring out how to map your classes to your real-world requirement.
I can post my code here if anyone’s interested.
Martin Breuss RP Team on Dec. 18, 2023
@Ash D I’d be interested! Can you maybe post it over at the end of the exercises course?
Ash D on Dec. 24, 2023
Ah, I didn’t know about that exercises course… will take a look
Become a Member to join the conversation.
Pythagoras on April 18, 2023
Some constructive critisism.
Happy with the your tutorial of classes and object orientation. Plenty of information to try to grasp but still not exhaustive to keep the learning- momentum optimal and not getting stuck on too much details.
That said, having a video of you doing the challenge after giving the participant the opportunity to think and do it for themselves is something that would be beneficial. Getting immediate feedback after trying for yourself on a blank slate truly elevates the learning-potential. Quite surprised to see that none of the tutorials have this.