I think this is also a valid point. Which is why I wouldn’t even start by telling @Groot to make a class. In fact, before assuming anything, I would ask them a little about their background. “Can I ask how much experience you have with coding?” or " Lets start by breaking the problem into smaller pieces - do you know what classes are?".
The last thing I want to do is give someone a piece of code that goes way over their head , because at that point, you’re not encouraging them to go out and learn by themselves - you’re just catching them a fish. (Admittedly, you example is pretty succinct and with some comments, self-explanatory)
Now, I’m not saying that you should never give out code (In fact, a lot of the threads on this forum are answered very succinctly with a link to a stackoverflow or a short example). But in some cases, like this, it’s better to teach them how to fish, rather than catching it for them. When I used to tutor in college, I would often help students who were several semesters below me in the math series. They were doing math I thought was trivial, which led to bad practices; it was much easier to just give them the answer to their problems, and move on. But I would see the same students again and again. What took more time, but benefitted them in the long run, was pushing them towards the answer. Teaching them how to approach a problem, as opposed to just giving them the answer, was definitely more time consuming. But what you find is that people are capable, and that most of the time, they can reach the answer by themselves - they just needed to be pushed in the right direction.
This last part is definitely valid point. For all I know, @Groot is a wicked smart dude, making line graphs like a champ out there after fiddling with your code.
Overall, I’m pumped that you’re out here looking to help others. But I ask that you consider the idea that “giving the answer” may not necessarily be helping them learn to learn.