Mar-12-2021, 11:48 PM
(Mar-12-2021, 11:38 PM)bowlofred Wrote: Your script is relatively fine for a quick script, but my concerns would be:
- You're performing input both inside and outside the function. I'd rather do it in one place.
- You're handling errors by recursion rather than a simple loop. Unlikely to be a huge problem, but not a good habit. Recursion has memory and depth limits that are smaller than some other cases. Don't invoke it arbitrarily. This case could be replaced with a loop and remove the recursion.
- Minor (and done in the example as well), but you're truncating inputs to int(). I see no reason to do so. This could handle float() input just as easily.
Thank you. I appreciate your suggestions here.
Quote:To "optimize" or "improve" it requires some metric to optimize against. Do you want it to be able to run faster? Have more understandable code? Be able to use as an example of OOP programming?
With my word choice of 'optimize', I didn't mean tweak to improve run-time performance. I meant make my code more understandable and readable. You've already provided three suggestions in this regard. Thank you for this. I will more carefully use the word 'optimize' in the context of programming especially on this forum but elsewhere too.