Table of Contents
Introduction
In this section of python coding, we will learn to calculate the simple interest. As we already know the mathematical expression to calculate the simple interest understand the code logic will be easier.
Let us look into the python code for calculating simple interest.
Program
def interest(p, r, t): amount = float(p) rate = float(r) time = float(t) s_interest = float((amount*rate*time)/100) print("Simple interest of principle amount {0} , rate of interest {1} and time period {2} is {3}".format(amount,rate,time,s_interest)) # User input p = input("Enter the principle amount: ") r = input("Enter the rate of interest: ") t = input("Enter the time period: ") interest(p,r,t)
OUTPUT
Explanation
In the above code, we have created a function interest(). The user inputs for principal amount, rate and time period are scanned through input() function and passed to the function interest() for calculating the simple interest and then storing the result in the variable s_interest.
0 Comments