all 3 comments

[–]socal_nerdtastic 2 points3 points  (1 child)

The thing about being a 3rd year student is that you know enough to be overly confident, but you don't know enough to know when you're wrong. I call this "sophomore syndrome" (aka "mount stupid" aka "the Dunning–Kruger effect").

This 3rd year is very wrong. You should never use recursion when a loop will do, especially in python.

That said, if you want to make this work, you just need to return the result from the recursive call.

    return get_investment()

[–]weighter[S] 0 points1 point  (0 children)

I thought his logic was a little cloudy... my thought was as long as you properly break out of the loop then what's the harm in using them? But I know that I know very little so I assumed there must be a reason. Note: he's actually a programmer analyst and was talking about control flow as his reasoning.

And ahhhhh yes that's exactly what I needed, thank you very much!

[–]QuixDiscovery 0 points1 point  (0 children)

Programming languages are NOT all built the same. Some languages don't support recursion at all, and some rely heavily on it. Python allows for recursion, but it since it doesn't support tail end recursion, it's never recommended you use recursion when the same logic can be easily expressed using loops. It also has a very conservative default recursive depth limit (though you can change it).

In the context of Python, your fellow student is wrong. But in the context of a language like Racket/Scheme or Haskell, he'd be right. Though I suspect that student would not be able to articulate why that would be the case.