Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My Answer: # TODO 1: Define the constants as instructed in the writeup and assign them # the correct values. INITIAL_PRINCIPAL = 10000.0 YEARS =

image text in transcribedMy Answer:

# TODO 1: Define the constants as instructed in the writeup and assign them

# the correct values.

INITIAL_PRINCIPAL = 10000.0

YEARS = 5

ACCOUNT_RATE_1 = 0.027

ACCOUNT_RATE_2 = 0.0268

ACCOUNT_RATE_3 = 0.0266

ACCOUNT_CMP_FREQ_1 = 1

ACCOUNT_CMP_FREQ_2 = 12

ACCOUNT_CMP_FREQ_3 = 365

# TODO 2: Implement the `amount_after_n_years` function.

def amount_after_n_years(init_principal, acc_rate, acc_cmp_freq, years):

n = acc_cmp_freq

r = acc_rate

t = years

A = init_principal * (1 + r)**(n*t)

return A

# TODO 3: Define the 3 `amount_*` variables and assign them the values as

# instructed in the writeup.

c1 = 10000 * (1 + 0.027) ** 5

c2 = 10000 * (1 + 0.0268 / 12) ** (5 * 12)

c3 = 10000 * (1 + 0.0266 / 365) ** (5 * 365)

def main():

print(c1, c2, c3)

print(max(c1, c2, c3))

amount_1 = amount_after_n_years(INITIAL_PRINCIPAL, ACCOUNT_RATE_1, ACCOUNT_CMP_FREQ_1, YEARS)

amount_2 = amount_after_n_years(INITIAL_PRINCIPAL, ACCOUNT_RATE_2, ACCOUNT_CMP_FREQ_2, YEARS)

amount_3 = amount_after_n_years(INITIAL_PRINCIPAL, ACCOUNT_RATE_3, ACCOUNT_CMP_FREQ_3, YEARS)

if __name__ == "__main__":

# TODO 4: Follow the instructions in the writeup to comment out the two

# print statements and uncomment the remaining lines of the code

# block.

main()

# print(f"Account option 1 will hold ${amount_1:,.2f}.")

# print(f"Account option 2 will hold ${amount_2:,.2f}.")

# print(f"Account option 3 will hold ${amount_3:,.2f}.")

# print(f"The maximum amount that can be reached is "

# f"${max(amount_1, amount_2, amount_3):,.2f}.")

print("After {} years, the initial principal of {:.2f} in account 1 with an interest rate of {} compounded {} times per year would grow to {:.2f}.".format(YEARS, INITIAL_PRINCIPAL, ACCOUNT_RATE_1, ACCOUNT_CMP_FREQ_1, amount_1))

print("After {} years, the initial principal of {:.2f} in account 2 with an interest rate of {} compounded {} times per year would grow to {:.2f}.".format(YEARS, INITIAL_PRINCIPAL, ACCOUNT_RATE_2, ACCOUNT_CMP_FREQ_2, amount_2))

print("After {} years, the initial principal of {:.2f} in account 3 with an interest rate of {} compounded {} times per year would grow to {:.2f}.".format(YEARS, INITIAL_PRINCIPAL, ACCOUNT_RATE_3, ACCOUNT_CMP_FREQ_3, amount_3))

Submission log file:

[ERROR] 2023-02-25 GMT-0500 08:21:50.778: An unexpected error has occurred.

Traceback (most recent call last):

File "", line 74, in run

File "", line 31, in generate_submission_archive

File "", line 51, in __list_files_for_submission

File "", line 65, in __generate_task_specific_files

File "", line 138, in task3

File "", line 24, in silent_import

File "", line 22, in silent_import

File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2800.0_x64__qbz5n2kfra8p0\lib\importlib\__init__.py", line 126, in import_module

return _bootstrap._gcd_import(name[level:], package, level)

File "", line 1050, in _gcd_import

File "", line 1027, in _find_and_load

File "", line 1006, in _find_and_load_unlocked

File "", line 688, in _load_unlocked

File "", line 883, in exec_module

File "", line 241, in _call_with_frames_removed

File "C:\Users\bwilliamson\Desktop\CSC\ppp-p1-types-variables-functions\task3a.py", line 40, in

table_volume = table_vol(TABLE_TOP_LENGTH, TABLE_TOP_WIDTH, TABLE_TOP_HEIGHT, TABLE_LEG_BASE_RADIUS, TABLE_LEG_HEIGHT)

File "C:\Users\bwilliamson\Desktop\CSC\ppp-p1-types-variables-functions\task3a.py", line 33, in table_vol

leg_vol = cylinder_vol(leg_base_rad, leg_height)

File "C:\Users\bwilliamson\Desktop\CSC\ppp-p1-types-variables-functions\task3a.py", line 23, in cylinder_vol

return 3.14.pi * base_radius ** 2 * height

AttributeError: 'float' object has no attribute 'pi'

[INFO] 2023-02-25 GMT-0500 08:21:50.781: Finding files for cleanup.

[INFO] 2023-02-25 GMT-0500 08:21:50.782: Cleanup finished.

[INFO] 2023-02-25 GMT-0500 08:21:50.782: Submission process FINISHED.

Your task is to, one last time, modify the code above so that it is more explicit and understandable. There is one file used in this task - . You will be making changes to this file. Start your work by opening the file in your Visual Studio Code. Find the line in the . To complete assign the following constants with the values as indicated. - First, define 2 constants for the initial principal that is deposited to the account and the number of years it will be kept there. Name the constants INITIAL_PRINCIPAL and YEARS respectively. Assign them with the values of 10000.0 and 5 . - Define 3 constants for the interest rates associated with each account with the following names: ACCOUNT_RATE_1, ACCOUNT_RATE_2, and ACCOUNT_RATE_3. Assign them with the following values: 0.027,0.0268, and 0.0266. - Define 3 constants for the yearly compounding frequency with the following names: ACCOUNT_CMP_FREQ_1, ACCOUNT_CMP_FREQ_2, and ACCOUNT_CMP_FREQ_3. Assign them with the following values: 1, 12, and 365 . In TODO 2, you will implement the amount_after_n_years function with the init_principal, acc_rate, acc_cmp_freq, and years parameters. The function returns the amount that is going to be on the account after the specified number of years based on the provided parameters. You will be using the following formula: A=P(1+nr)nt - A : final amount - P: initial principal balance - r :interest rate - n : number of times interest applied per time period ( acc_cmp_freq) - t : number of time period elapsed For more details, please, refer to this tutorial. In TODO 3 , you will define - amount_3 variables ( 3 altogether) and assign each with the value returned by the amount_after_n_years. For each variable, the amount_after_n_years function call needs to be provided with the matching arguments from constants defined in TODO 1. For example, the correct assignment to the amount_1 variable looks like this: \[ \begin{array}{l} \text { amount_1 = amount_after_n_years (INITIAL_PRINCIPAL, ACCOUNT_RATE_1, } \\ \text { ACCOUNT_CMP_FREQ_1, YEARS) } \end{array} \] Finally, in TODO 4 , replace the existing print statements with the more informative ones that are currently commented out, i.e. marked with the \# prefix. You are required to go about this by commenting out the original two print statements by adding \# at the beginning.. Then, uncomment the 5 lines that are originally commented out by removing "\#" at the beginning. Note that you cannot just delete the two original print statements - that would result in you not obtaining the full score for this activity

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

Explain the key areas in which service employees need training.

Answered: 1 week ago

Question

Understand the role of internal marketing and communications.

Answered: 1 week ago