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)

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay