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.
# 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.
Practical List - Python [ 4330701 ] [ PRACTICAL EXERCISES ] - Computer Bits Daily
0 Comments