Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack ExchangeStack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Explore Stack InternalOne of the easiest ways to understand and debug code is to put print statements everywhere and then figure out why you are getting the results printed. This is especially important when first starting to code and given homework assignments. The code you posted appears to show that you tried something and probably thought about it awhile then tossed in the towel and went and asked for help. Most experienced programmers would rather see novices develop debugging skills instead of being constantly available to work through practice algorithms with them.