In this example we will show how to write Python codes to calculate single and compound interests. The input data include principal, annual interest rate, and time.
Source Code
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
principal = float(input("Enter the principal:"))
rate = float(input("Enter the rate(annual interest rate):"))
time = int(input("Enter the time(years):"))
#Simple interet
simpleInterest = principal * rate / 100 * time
#Compund interest
compoundInterest = principal * (1 + rate / 100) ** time - principal
print("The simple interest is:", simpleInterest)
print("The compound interest is:", compoundInterest)
Output:
Enter the principal:100000
Enter the rate(annual interest rate):10
Enter the time(years):40
The simple interest is: 400000.0
The compound interest is: 4425925.55681761