Ask Question

Complete the function doubling_time that takes two parameters bal and apr and uses a while loop compute the number of years it takes for the initial balance in a bank account to double in value rounded up to the nearest year. The two parameters are: bal: initial balance in the bank account apr: annual percent interest income, this is the percentage (of the balance) that should be added to the balance every year as interest income. For example, if bal is 200 and apr is 10 then the balance should be 220 after the first year. Provided definition: # returns the doubling time of the balance in whole years def doubling_time (bal, apr) :

+1
Answers (1)
  1. 1 July, 05:51
    0
    def doubling_time (bal, apr) : current_amount = bal year = 0 while (current_amount < bal * 2) : current_amount = current_amount + (current_amount * apr / 100) year + = 1 return year print (doubling_time (200, 10))

    Explanation:

    The solution is written in Python 3.

    Firstly create a function that takes two input bal and apr (Line 1). Next set the bal as current amount (Line 2) and create year variable as a counter of year (Line 3).

    Create a while loop and set the loop condition to enable the while loop persist so long as the current amount still less than the double of initial balance (Line 4). In the while loop, apply formula to compute the current amount after adding the annual interest and then increment year counter by one (Line 5 - 6). The year counter will keep increment until the current amount is double the initial balance and terminate the while loop. Return the year counter as function output (Line 8).

    We test the function by passing 200 and 10 as initial balance and annual interest rate, respectively. We shall get return value 8.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Complete the function doubling_time that takes two parameters bal and apr and uses a while loop compute the number of years it takes for ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers