Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python question If p is the bank\'s interest rate in percent per year, an initia

ID: 3662827 • Letter: P

Question

Python question

If p is the bank's interest rate in percent per year, an initial amount a will grow after n years to a(1 + p/100)^n. Write a Python function growth (a, p, n) that returns the growth. Place your function in the file Q1_yourmacid.py. For example, if you macid is liutm, your file must be called Q1_liutm.py. The parameters can be floating-point numbers and the result should be a floating-point number. Which parameter values would you use to test your implementation? You do not have to include your test cases, but you should test your implementation yourself. Example: Write two Python functions, minutes (d: 'days', h: 'hours', m: 'minutes') that returns the number of minutes in the period of d days, h hours, and m minutes, and function daysHoursMinutes (m: 'minutes') that returns a triple with how many days, hours (between 0 and 23), and minutes (between 0 and 59) correspond to m minutes. Examples: The parameters of both functions can be any non-negative integers. Put both functions in the file Q2_yourmacid.py. Use the two functions for testing by converting days, hours, minutes to minutes and back again to days, hours, minutes. What would be good test cases to reveal errors? Note that it is common in software development to write extra code for the sole purpose of testing. You do not have to include your test cases.

Explanation / Answer

Answer for question1:

Q1_yourmacid.py

------------------------------------------------

import math
def growth(a,p,n):
   if(a < 0 or p < 0 or n < 0):
       print("Invalid input")
       return "Invalid input"
   else:
       #growth = a (1+p/100)^n
       growth = a * math.pow((1+p/100),n)
       return growth

------------------------------------------------------------------

Q1_liutm.py

--------------------------------------------------------------------

import Q1_yourmacid

from Q1_yourmacid import growth
print(" a =100, p = 5, n = 2, growth=",growth(100,5,2))
print(" a =100, p = 5, n = 2, growth=",growth(250.50,3.2,8))
print(" a =-100, p = 5, n = 2, growth=",growth(-100,5,2))
print(" a =-100, p = 5, n = 2, growth=",growth(100,-5,2))
print(" a =-100, p = 5, n = 2, growth=",growth(100,5,-2))

----------------------output----------------------------

a =100, p = 5, n = 2, growth= 110.25
a =100, p = 5, n = 2, growth= 322.2888705860897
Invalid input
a =-100, p = 5, n = 2, growth= Invalid input
Invalid input
a =-100, p = 5, n = 2, growth= Invalid input
Invalid input
a =-100, p = 5, n = 2, growth= Invalid input