Compound Interest Calculator
Calculate compound interest with a chosen frequency. Students distinguish a per-period rate from an annual rate and multiply years by periods per year.
1# Take inputs2principal = float(input("Enter principal: "))3rate = float(input("Enter rate (%): "))4time = float(input("Enter time (years): "))5compounds = int(input("Enter compounds per year: "))67# Calculate8amount = principal * (1 + rate / (100 * compounds)) ** (compounds * time)9interest = amount - principal1011print(f"Compound Interest: {interest:.2f}")12print(f"Total Amount: {amount:.2f}")
Output
Enter principal: 10000 Enter rate (%): 5 Enter time (years): 2 Enter compounds per year: 12 Compound Interest: 1049.41 Total Amount: 11049.41
In this one
- Convert annual to periodic rates
- Count compounding periods
- Separate interest from amount
How it works
- 1
Read principal, annual rate, years, and frequency.
- 2
Raise the periodic growth factor to frequency times years.
- 3
Subtract principal and print interest and final balance.
Edge cases
What if compounds is zero?
What if compounds is zero?
The periodic-rate calculation raises ZeroDivisionError.
Is amount the same as interest?
Is amount the same as interest?
No. amount includes the original principal.
What's going on
The base factor is 1 + rate / (100 * compounds). Raising it to compounds * time applies that factor once per compounding period.
amount is the grown balance; subtracting principal gives interest alone. Twelve periods means monthly compounding under this formula, not twelve percent interest. A frequency of zero divides by zero, so frequency must be positive. The .2f display does not remove floating-point approximation.
What if compounds is zero? The periodic-rate calculation raises ZeroDivisionError.
Is amount the same as interest? No. amount includes the original principal.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
What is the exponent?
Pick an answer to check it.
Question 2
What if compounds is zero?
Pick an answer to check it.
Questions people ask
What if compounds is zero?
The periodic-rate calculation raises ZeroDivisionError.
Is amount the same as interest?
No. amount includes the original principal.
What is the exponent?
compounds * time.
๐Related Content
- ๐
Phase 6 - Learn Concepts
Review Phase 6 concepts and explanations
- ๐
Phase 6 - Quiz
Test your Phase 6 understanding with quiz questions
- ๐ป
Phase 6 - All Practice Problems
Explore all practice problems for Phase 6
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum