Skip to Main Content
Blog

Calculate Compound Interest in Python

Calculate Compound Interest in Python

Enter P: 10000
Enter R: 6
Enter T: 2
Interest: 1236.0
Amount:   11236.0
def main():
	p = int(input("Enter P: "))  # Principal
	r = float(input("Enter R: "))  # Rate of interest
	t = int(input("Enter T: "))  # Time in years

	a = p * (1 + r / 100) ** t  # Amount after time
	i = a - p  # Compound interest

	print("Interest:", i)
	print("Amount:  ", a)


if __name__ == "__main__":
	main()