# Python program to calculate simple and compound interest.

Are you looking to calculate interest on a loan or investment using Python? Whether you're a student just learning to code or a seasoned developer, understanding how to calculate simple and compound interest is a valuable skill.

In this article, we'll show you how to write a Python program to calculate simple and compound interest, and we'll explain some basic concepts related to interest.

First, let's define some terms related to interest:

Principal (P): The amount of money borrowed or invested.
Rate (R): The annual interest rate as a percentage.
Time (N): The length of time the money is borrowed or invested.

Simple interest is calculated using the formula: Simple interest = (P * N * R)/100 Compound interest is calculated using the formula: Compound interest = P * (pow((1 + R / 100), N))

#### Now, let's dive into the Python code. We'll start with the simple interest calculator:

# Get the principal, rate, and time from the user principal = float(input("Enter the principal amount: ")) rate = float(input("Enter the annual interest rate: ")) time = float(input("Enter the time period in years: ")) # Calculate the simple interest simple_interest = (principal * rate * time) / 100 # Print the result print("Simple interest is:", simple_interest)

Explanation:

In this code, we first get the principal, rate, and time from the user using the input function. Then, we calculate the simple interest using the formula we defined earlier. Finally, we print the result using the print function.

Now, let's move on to the compound interest calculator:

# Get the principal, rate, and time from the user principal = float(input("Enter the principal amount: ")) rate = float(input("Enter the annual interest rate: ")) time = float(input("Enter the time period in years: ")) # Calculate the compound interest Amount = principal * (pow((1 + rate / 100), time)) # Print the result CI = Amount - principal print("Compound interest amount is", CI)

#### Explanation:

This code is similar to the previous code, except that we're using the formula for compound interest. We use the pow function to raise (1 + rate / 100) to the power of time.

Note that in both programs, we're using the float function to convert the user input to a floating-point number.
This allows us to perform arithmetic operations on the input.

In conclusion, calculating simple and compound interest is a useful skill that can be easily accomplished with Python. By using the formulas we defined earlier and some basic Python programming concepts, you can create a simple and effective interest calculator.

Practical List - Python [ 4330701 ] [ PRACTICAL EXERCISES ] - Computer Bits Daily