Skip to content
Advertisement

Question regarding my program being tedious

I just started learning python 3 recently and i have a problem of my code being too repetitive and lengthy.

i wrote a code to calculate the interest earned. I have read about using functions to simplify my code but i am not sure how to go about doing this.

Thanks for anyone who is willing to help me out! The code i have written is as follows:

JavaScript

Advertisement

Answer

This is about as concise as I can make it with a quick pass.

I refactored things so all inputs are requested first, all computation done second. Should you refactor the calculation bits into a function, that’d make the function easier to test. I also refactored the computation into a function of its own.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement