×

Python Simple Interest

Python is an Object-Oriented high-level language. Python has an English-like syntax, which is very easy to read and write codes. Python is an interpreted language which means that it uses an interpreter instead of the compiler to run the code.

The interpreted language is processed at the run time thus takes less time to run. Python has dynamic semantics and has high-level built-in data structures which support dynamic typing and dynamic binding. Python provides rapid development.

While learning a language, we would like to do many basic programs, one of which is calculating simple interest. Simple interest is used in banks and the financial sector to calculate interest charges on the total amount. The Simple interest is calculated on the main loan amount.

This amount is also termed as Principal. To calculate the simple interest, we need the principal amount, time period, and rate of the interest. This program is very easy to code, and we will get the knowledge of user input and operations like multiplication, division, etc.

In this post, we will discuss how to calculate the Simple Interest in Python. The formula for calculating the simple interest is:

Simple Interest = (P x R x T)/100

Where

P = Principal Amount

R = Rate of Interest

T = Time Period

Before writing the actual code, we will write the algorithm for the program. It is always wiser to write an algorithm because it makes the logic easier to understand. These are some of the advantages of algorithms:

  • Better Readability
  • We can write code in any language after writing the algorithms
  • Helps in debugging

So let us write the algorithms to calculate the simple interest:

1. Read the PrincipalPrincipal, or declare it in the code.
2. Read the Rate, or declare it in the code.
3. Read the Time, or declare it in the code.
4. Apply the formula.
5. Print the calculated Simple Interest.

In this post, we are going to make two programs, one in which we define all the variables in the code itself, and the other we will take the input from the user.

Python Program

def Simple_Interest(P,R,T):
	SI = (P*R*T)/100
	return SI
P = 1000
R = 4
T = 1
SI = Simple_Interest(P,R,T)
print(“The simple Interest is: “, SI)

Output

The simple interest is: 40.0
Simple Interest in Python

Complexity

Since this program does not have any loop, and only calculation, so the complexity of this program is 0(1).

Explanation

In the code above, we have defined the Principal amount and declared the variable as P, the value for P is 1000, the time period for the loan amount as T, the rate of interest as R.

Then we have passed these values to the function Simple_Interest, in which we are using the formula to calculate the simple interest and returning the result. In the end, we are printing the result.

Simple Interest by User Input

In this code, we will read the values of Principal, Interest and time from the user instead of directly hard coding it.

def Simple_Interest(P,R,T):
	SI = (P*R*T)/100
	return SI
P = float(input(“Enter the Principal amount: “))
R = float(input(“Enter the Rate of Interest: “))
T = float(input(“Enter the Time Period: “))
SI = Simple_Interest(P,R,T)
print(“The simple Interest is: “, SI)

Output

The simple interest is: 40.0
Simple Interest in Python

Explanation

The only difference between this code and the above code is that in this code, we are taking inputs from a user.

In the 4,5,6 lines of code, we have taken the user input of Principal amount, rate of interest, and time period. In Python, the inputs are taken by using the input() method. The input() method reads the input as a string, so we need to convert it into either float or integer to do any mathematical operation. We are converting the input to float by using the float() method.

After this, we are again calling the function and using the formula, and printing the result.


Related Topics

Python isinstance() function

Python isinstance() function The isinstance() function in Python returns a Boolean value ‘True’ if the given object is of the specified type, otherwise it returns False. Syntax isinstance(object, classinfo) Parameter object: It is a required parameter which represents an object. classinfo: This...

1 minute read.

Introduction to Scratch programming

Scratch programming is generally designed for children who may create digital stories, games, and animations using the computer language Scratch, which has the largest kid-focused community in the world. Scratch...

3 minutes read.

Python Typing Module

An Introduction to the Typing Module The typing module is introduced in Python version 3.5 and used to provide hinting method types in order to support static type checkers and linters...

10 minutes read.

Excel Automation with Python

Data analysis is the upcoming technology in the IT sector; this data analysis can be performed easily with the help of data frames or by using excel sheets. The data...

4 minutes read.

How to comment out a block of code in Python

When you are writing code in Python, you may want to document it. You need to mention why a piece of code functions, for instance. Mathematics, algorithms, and intricate business...

4 minutes read.

Python Packages

A package is a collection of Python modules that share a similar namespace and are generated by putting all of the modules in a single directory with certain special files...

6 minutes read.

Python program to convert Celsius into Fahrenheit

Python program to convert Celsius into Fahrenheit This program explains how we can take the temperature in Celsius and convert them into Fahrenheit. Celsius Celsius, also known as centigrade, is a measurement unit...

1 minute read.

Fsolve in Python

Python Programming Language Python programming language is one of the most used programming languages, as it is used widely in the field of software and data analysis, web development, etc. It...

3 minutes read.

SKLearn Clustering

These are ml methods thatare responsible for detecting patterns and the similarities within the data.The clustering methods are unsupervised.Here the data is clustered to form groups with the help of...

3 minutes read.

Insertion Sort using Python

Insertion sort is a type of sorting technique that is used for sorting an array with random elements. Using sorting methods, any unsorted array can be sorted into ascending or...

3 minutes read.

Binary Search Visualization using Pygame in Python

A calculation like Binary Search is seen effectively by picturing. Here in this tutorial, a function that pictures the Binary Search Algorithm is carried out. The Graphical User’s Interface (GUI)...

15 minutes read.

Confusion Matrix Visualization Python

The confusion matrix is a two-dimensional array that compares the anticipated and actual category labels. These are the True Positive, True Negative, False Positive, and False Negative classification categories for...

4 minutes read.

Function annotations() in Python

What is Function Annotations? Function annotations provide a way related to different parts of a function at compile time with arbitrary Python expressions. It doesn’t have life in Python runtime execution....

3 minutes read.

Append key Value to Dictionary in Python

The Python dictionary is one of the built-in data types. Elements of dictionaries are key-value pairs. In Python, there are numerous ways to add dictionaries. Let's examine some of the...

9 minutes read.

Python Parser

Introduction : Parsing is referred to as the processing and translation of a Python program into machine language. In general, we could indeed say that the command parse is used to...

4 minutes read.

Python Struct

Python Python is an interactive and more accessible language than any other programming language. The python programming language uses a variety of libraries to perform the operations in a faster way....

3 minutes read.

App Config Python

An XML file called App. Config serves as the document for any programme. In other terms, you can modify any configuration inside of it without going to edit the code...

7 minutes read.

Linear Regression using Sklearn with Example

This article will examine Python's global, local and non-local variables and show you how to use them to write code without problems. Let's quickly review what a variable in Python is...

8 minutes read.

How To Compare Two Strings In Python

In this article, we will discuss how to compare two strings in Python. So, before that, let’s have a quick revision on “What are strings?” Strings are a sequence of characters that...

5 minutes read.

Python sorted() function

Python sorted() function The sorted() function returns a sorted list of the specified iterable object. Syntax sorted(iterable, *, key=None, reverse=False) Parameter iterable: It is a required parameter that represents the sequence to sort, list, dictionary, tuple etc. key:...

1 minute read.