Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this assignment. Here is the code below to modify. This is the starting code. Thank you. You will need IDLE and

image text in transcribed

I need help with this assignment. Here is the code below to modify. This is the starting code. Thank you. You will need IDLE and a recent edition of Python (I use Python 3.8.1).

def calculate_future_value(monthly_investment, yearly_interest, years): # convert yearly values to monthly values monthly_interest_rate = yearly_interest / 12 / 100 months = years * 12

# calculate future value future_value = 0.0 for i in range(0, months): future_value += monthly_investment monthly_interest = future_value * monthly_interest_rate future_value += monthly_interest

return future_value

def main(): choice = "y" while choice.lower() == "y": # get input from the user monthly_investment = float(input("Enter monthly investment:\t")) yearly_interest_rate = float(input("Enter yearly interest rate:\t")) years = int(input("Enter number of years:\t\t"))

# get and display future value future_value = calculate_future_value( monthly_investment, yearly_interest_rate, years)

print("Future value:\t\t\t" + str(round(future_value, 2))) print()

# see if the user wants to continue choice = input("Continue? (y): ") print()

print("Bye!") if __name__ == "__main__": main()

Enhance the Future Value program Senie/ Erenl al 136 Exercise 4-1 In this evemcise you Wenhance the Future Value program in figure 3-15 so it validates he three user entries with messages that are something like these: Chapter 4 How to define and use functions and modules 7. Modity the main() function so it uoes the pet flouto function for the first two 139 entries. The low and high aguments should he l and 1000 for the first entry. and 0 and 15 for the second entry. S Add a get int) function that works lke the pst flouO funstion, except thiat n gets an integer entry instead of a fBoat entry Then, call this function from the maini) function so it gets the years entry. elne te the Puture Value Caleulator tty at le greater than o and leas than or egual to 1000 L00 feter scataly iavestatr nter sonthty leveatnent: nter yearly intereet rater tty et 2e greeter ha 0 and less than or equal to 15 200 Create a validation module Use the File-Save As command to save a copy of the Future Value program as validation.py. This will be the file for a module that stcres the get oato and get int) functions. So, delete the calculate future value() function, but keep the main) function and the if statement after the main) function. 10. Ie the main) function, delete everything inside the while Joop except the last statement that asks whether the user wants to continue. Within this loop, code two call statements that test the get_Boan(0 and get int) functions. 11. Run the program to test the two functions. When vou're through. you can 16 9. 12 Rcer yearly intereat ate acer sunber of yeare: paty t be greater than 0 and less than or equal to 50 20 ater pusber of yeare: 23233.91 Pture Valse. Coet inue (y/al7a I a NE open the future_valoe py file that's in this folder: ythes/exercises/cho4 close the file. Use the validation module in the Future Value program 12. Go back to the future value py file. Then, commeng out the get number and 2. Test the prongram, hut remember that it doesn't do any validation, so enter valid numbers get integer() functions. 13. Add an import statement that imports the validation module. Add two validation functions to the program 3 la prepuration for adding two functions named get float() and get into to the program, create a hierarchy chart or outline that includes those function The functions will he used to get valid numbers and integers from the user descrihed in the next steps. 14. Modify the code in the main() function so it uses the functions in the validation module. 4. Add a function named get float() to the program. This function should accent one argument, which is a prompt like "Enter monthly investment: ". Then, this function should use the input function to get an entry from the user using the prompt that's passed to it, and the entry should be converted to a float value. Next, this function should check this entry to make sure it's greater than 0. If it is, the entry is valid and the number should be returned to the calling statement. If it isa't, an appropriate eror message should be displayed, and the user should enter another value. To make this work, the function should use a while statement that gets an entry until it is valid. 5. Modify the main() function so it uses this function to get the monthly imestment entry. That tests the function. 6. Enhance the get foat) function so it gets three arguments: a prompl, a low validity value, and a high validity value, This function should work as before, eAcept the entry must be greater than the low value and less than or equal to the high value. If the entry is invalid, this function should display error messages like those above using the low and high arguments. OtherWise, should return the value to the calling statement

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

How is the NDAA used to shape defense policies indirectly?

Answered: 1 week ago