Part of the series

Several example codes

~1 min read • Updated Oct 12, 2025

Program Overview

This Python program receives the initial bank account balance, the annual interest rate, and a target amount.
It calculates how many years it will take for the balance to reach the target amount without any withdrawals.
Each year, the balance increases based on the interest rate.


Python Code:


def years_to_target(balance: float, interest_rate: float, target: float) -> int:
    years = 0
    while balance < target:
        balance += balance * interest_rate / 100
        years += 1
    return years

# Read inputs from user
balance = float(input("Enter initial account balance: "))
interest_rate = float(input("Enter annual interest rate (%): "))
target = float(input("Enter target amount: "))

years = years_to_target(balance, interest_rate, target)
print(f"To reach {target:.2f}, it will take {years} years.")

Sample Output (input: balance = 100000, interest = 10%, target = 200000):


To reach 200000.00, it will take 8 years.

Step-by-Step Explanation:

- The user enters the initial balance, interest rate, and target amount
- The program uses a loop to simulate yearly growth
- Each year, the balance increases by the interest
- The loop continues until the balance reaches or exceeds the target
- The number of years is then displayed


Written & researched by Dr. Shahin Siami