Question: For this assessment, you will write a function that for a given invested amount will return that amount plus the calculated investment gains. If the

For this assessment, you will write a function that for a given invested amount will return that amount plus the calculated investment gains. If the given amount is greater than the $1 million threshold, the app will need to increase the rate of return 1% for every million dollars invested plus the original rate of 0.1%. Finally, you will implement the functionality to estimate (forecast) the return on investment over a time period.
In order for you to start this project, we will provide a function template that can be followed to solve this challenge. The code block below is a sample way that this project could be structured.
# global variable def calculate_gains(amount_inv=0.0): """ Calculating the return gains of an investment. # base amount gain margin if amount_inv >1000: # check whether the invested amount is greater than the multiplier amount # gather the value of the division # update the `gain_margin` by the multiplier mod # calculate the total amount of gains # calculate the total amount plus the gain margin # return the gains, the full amount and the gain margin
Create a user-defined function called calculate_gains(), which receives the amount desired to be invested. Outside this function, create a global variable, multiplier_amount that would be accessible at any point in your code to store the "multiplier amount", which will be the amount that would trigger the increase on the gain margin in case the invested amount is greater than this value. In our case, this amount is set to 1 million.
Inside your function, create a variable to store the gain margin, which is 0.1% by default. Also create variables for total_gains and total_amount, setting default values to 0. After these declarations, the first thing to check is whether the amount invested is greater than 1000(one thousand), which is the minimum application value to start using the app.
Next, check if the amount is greater than the multiplier value (1 million). If it is greater, then update the gain margin variable with the new gain margin and add the estimated amount to the original amount, otherwise just multiply the values to obtain the return on investment for the given amount.
Finally, you need to return the total gains amount, the amount invested updated with the return on investment added to it, as well as the gain margin (the ordering is important for testing purposes). To test your function, enter the following amount: 2000000($2 million).
To summarize:
In the user-defined function declare a global variable inside the python file to store the multiplier amount.
Declare a variable to store the gain margin.
Declare variables to store the total gains and the total amount.
Check if the amount is greater than the minimum value (which is 1000).
Check if the amount is greater than the multiplier amount (which is 1000000).
If so, update the gain margin.
Calculate the total gains by multiplying the gain margin by the amount.
Return the total gains, total updated amount, and gain margin.
Example:
Input : calculate_gains(amount_inv=2000000)
Output: (42000.0,2042000.0,0.021)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!