Simple Interest is calculated using the principal amount, time period, and rate of interest. In Python, a function can be used to calculate Simple Interest and return the result.
- Example: if P = 1000, T = 2 years, and R = 5%, the Simple Interest is 100.0.
- Simple interest formula : (P x T x R)/100
Using function
A function can be defined to calculate Simple Interest using the given principal, time, and rate values.
Pythondef simple_interest(p, t, r):
return (p * t * r) / 100
p = 1000
t = 2
r = 5
result = simple_interest(p, t, r)
print(result)
Output
100.0
Explanation:
- simple_interest() defines a function to calculate Simple Interest.
- p, t, and r represent principal, time, and rate.
- (p * t * r) / 100 applies the Simple Interest formula.
- return sends the calculated interest back to the function call.
- simple_interest(p, t, r) calls the function with the given values.
Using Function with User Input
Pythondef simple_interest(p, t, r):
return (p * t * r) / 100
p = float(input("Enter principal: "))
t = float(input("Enter time: "))
r = float(input("Enter rate: "))
result = simple_interest(p, t, r)
print("Simple Interest:", result)
Output:
[Screenshot-2026-08-13-122627] Explanation:
- input() takes the principal, time, and rate from the user.
- float() converts the input values into numbers.
- simple_interest() calculates the interest using the formula.
- result stores the calculated Simple Interest.
Using lambda function
A lambda function can perform the Simple Interest calculation in a single expression.
Pythonsi = lambda p, t, r: (p * t * r) / 100
p, t, r = 8, 6, 8
res = si(p, t, r)
print(res)
Output
3.84
Explanation:
- lambda p, t, r creates an anonymous function with three parameters.
- si stores the lambda function.
- si(p, t, r) calls the lambda function with the given values.
- result stores the returned value.
Using list comprehension
List comprehension can also be used to perform the calculation and extract the result from a single-element list.
Pythonp, t, r = 8, 6, 8
si = [p * t * r / 100][0]
print(si)
Output
3.84
Explanation :
- [p * t * r / 100] creates a list containing the calculated value.
- [0] accesses the first element of the list.
- si stores the resulting value.
Note: List comprehension is generally used for creating lists from iterable data. It is not necessary for calculating a single value, but it can be used to demonstrate another Python approach.