How to Calculate Simple Interest in Python

In this tutorial, we will program 'How to Calculate Simple Interest in Python.' We will learn how to calculate the actual amount of simple interest. The objective is to find the simple interest for given principal, rate, and time values. I will provide a sample program to demonstrate the actual coding process in this tutorial.

This topic is very easy to understand. Just follow the instructions I provide, and you can do it yourself with ease. The program I will show you covers the basics of programming to get the actual simple interest amount. I will do my best to provide you with a simple method for calculating simple interest. So, let's start with the coding.

Getting Started:

First you will have to download & install the Python IDLE's, here's the link for the Integrated Development And Learning Environment for Python https://www.python.org/downloads/.

Creating Main Function

This is the main function of the application. The following code will display a simple GUI in terminal console that will display program. To do this, simply copy and paste these blocks of code into the IDLE text editor.
  1. def simple_interest(p,t,r):
  2.         print('The principal is', p)
  3.         print('The time period is', t)
  4.         print('The rate of interest is',r)
  5.        
  6.         si = (p * t * r)/100
  7.        
  8.         print('The Simple Interest is', si)
  9.         return si
  10.        
  11.  
  12.  
  13.  
  14. ret = False
  15.  
  16.  
  17. while True:
  18.         print("\n================== Calculate Simple Interest ==================\n\n")
  19.  
  20.  
  21.         p = int(input("Enter principal: "))
  22.  
  23.         t = int(input("Enter Time Period: "))
  24.  
  25.         i = int(input("Enter Interest: "))
  26.  
  27.         print("\n")
  28.        
  29.         simple_interest(p, t, i)
  30.  
  31.         opt = input("\nDo you want to try again?(yes/no): ")
  32.  
  33.         if opt.lower() == 'yes':
  34.                 ret=False
  35.         elif opt.lower() == 'no':
  36.                 ret=True
  37.                 print("Exiting program....")
  38.  
  39.         else:
  40.                 print("Please enter yes/no:")
  41.                 break
  42.  
  43.         if ret == False:
  44.                 continue

This script calculates the simple interest based on user-provided inputs for principal, time period, and rate of interest. It repeatedly prompts the user to input these values, calculates the simple interest using the given formula, and displays the result. After each calculation, the user is asked if they want to try again, allowing them to either continue or exit the program.

Output:

There you have it we successfully created How to Calculate Simple Interest in Python. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!

More Tutorials for Python Language

Python Tutorials

Add new comment