Question

From Zelle chapter 8: Write a program that uses a while loop to determine how long...

From Zelle chapter 8:

Write a program that uses a while loop to determine how long it takes for an investment to double
at a given interest rate. The input will be an annualized interest rate, and the output is the number of
years it takes an investment to double. Note: the amount of the initial investment does not matter; you
can use $1.

Hint: Chapter 2 futval.py has code with a for-loop that computes the value of an investment over 10 years.
That program shows how an investment grows form one year to the next.
futval.py used eval to covert the rate that was input, but you should use float.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

*** Please Give proper indentation, as shown in the image of the code ***

####################################################################################################

# Function to calculate Simple Intrest
def Simple_Intrest(principle_amount, rate_interest, investment_years):
intrest = (principle_amount*rate_interest*investment_years)/100 # Formula for simple intrest
final_amount=principle_amount+ intrest # calculating Final amount
return final_amount

# main function
def main():
# input
principle_amount=float(input("Please Enter The Principle Amount : "))
rate_interest=float(input("Please Enter The Rate Of Intrest : "))
cur_amount=principle_amount
investment_years=0

# while loop to calculate answer
while cur_amount < 2*principle_amount:
investment_years+=1
cur_amount=Simple_Intrest(principle_amount, rate_interest, investment_years)
# Answer
print("{} take {} years to be doubled witn an intrest of {}".format(principle_amount, investment_years, rate_interest))

  
main()


####################################################################################################

Output :

Add a comment
Know the answer?
Add Answer to:
From Zelle chapter 8: Write a program that uses a while loop to determine how long...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program in Python that computes the interest accrued on an account. You can modify...

    Write a program in Python that computes the interest accrued on an account. You can modify the “futval.py” program given in Chapter 2 to accomplish it. Your program should use a counted loop rather than a formula. It should prompt the user to enter the principal amount, the yearly interest rate as a decimal number, the number of compounding periods in a year, and the duration. It should display the principal value at the end of the duration. To compute...

  • Chapter 2 slides 40 to 47 discuss an example program, which computes the future value of...

    Chapter 2 slides 40 to 47 discuss an example program, which computes the future value of an investment given an initial principal and an interest rate. Your task is to modify this program to calculate and print the future values of an investment after 10 years, using several different interest rates.: from 1% to 20%, in increments of 1%. That is, given an initial principal, your program should compute the future value after 10 years given an interest rate of...

  • Write a java program that makes use of the ‘DO WHILE ’ loop. The program asks...

    Write a java program that makes use of the ‘DO WHILE ’ loop. The program asks a user to enter information about several of their friends. The information is their last name, the state they live in, their age, and their expected graduation year. After you enter one friend, write out each individually. You must use JOptionPane to input the 4 fields, and to output the 4 fields. Refer to the textbook Code Listing 4-6 to see how to use...

  • Objectives: Use the while loop in a program Use the do-while loop in a second program...

    Objectives: Use the while loop in a program Use the do-while loop in a second program Use the for loop in a third program Instructions: Part A. Code a for loop to print the Celsius temperatures for Fahrenheit temperatures 25 to 125. C = 5/9(F – 32).Output should be in a table format: Fahrenheit Celsius 25 ? . . . . . . . . Turn in the source and the output from Part A. Part B. Code a while...

  • Write a C program that computes Pi with the approximation algorithm that I introduced in class....

    Write a C program that computes Pi with the approximation algorithm that I introduced in class. I want you to write the program in two different ways: The first version will add up the first 28284277 elements of the approximation series in a simple for loop. I ask you to put the code into a function with this signature: float get_pi_for(void); The second version will break out of a while loop depending on whether a pair of adjacent elements (remember...

  • PYTHON CODE: Write a program that uses a while loop to examine every integer from 999...

    PYTHON CODE: Write a program that uses a while loop to examine every integer from 999 down to zero and generate the exact same output as shown blow. The range function is not required. NOTE: you must use a while loop. Required Output 960 920 880 840 800 760 720 680 640 600 560 520 480 440 400 360 320 280 240 200 160 120 80 40

  • a) Write a program that uses a while loop to print all divisors of a number...

    a) Write a program that uses a while loop to print all divisors of a number supplied by the user. The program should also print the sum of all the divisors and whether the number the user entered is a prime number or not. Note: The definition of a divisor is a number that divides another evenly (i.e., without a remainder) and the definition of a prime number is a number whose only divisors are 1 and itself. b) Implement...

  • C++ program by using while loop structure. Write an interactive program (C++) to prompt and read...

    C++ program by using while loop structure. Write an interactive program (C++) to prompt and read two float type numbers, Then your program should perform and print the following arithmetic: (use while loop structure to repeat program 2 times. 1) Sum 2)Difference 3) Product 4) Quotient 5) Modulus (use system defined fmod function) You must use system's defined function prototype and/or to create programmer's defined function prototype for each of the above calculation. In addition, create a function called "DISPLAYLINE...

  • Write a program that prints the accumulated value of an initial investment invested at a specified...

    Write a program that prints the accumulated value of an initial investment invested at a specified annual interest and compounded annually for a specified number of years. Annual compounding means that the entire annual interest is added at the end of a year to the invested amount. The new accumulated amount then earns interest, and so forth. If the accumulated amount at the start of a year is acc_amount, then at the end of one year the accumulated amount is:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT