DEV Community

Sachin pagar
Sachin pagar

Posted on

How to write python program to calculate simple interest

The Original article link is Available so let's see :
We need to make sure that only numbers are inputted while asking for input.
To do that, I am going to put each input statement in its own while loop. The while loop will be exited when a number is inputted. Checking if the value inputted is correct is done by checking if it can be converted into a floating-point number. Since converting a string containing characters other than numbers into floating-point numbers results in a traceback, I am using try and except block to achieve this part.
In the try block I am trying to convert input into floating point value. If an error occurs then the flow jumps to except block where I am just going to ask the loop to continue. This goes on until a valid input is given.
For detailed coding see below original Article
How to write python program to calculate simple interest

Top comments (0)