ISGB 7990 Homework: 4 – Defining Functions

$35.00

Download Details:

  • Name: Homework4-jv2wlj.zip
  • Type: zip
  • Size: 126.14 KB

Category:

Description

5/5 - (1 vote)

Part A
We would like to sing Happy Birthday to the user of our code, adjusting the song to include the user’s
name.
Your code must:
1. Define a function that accepts one argument: the user’s name. This function should print:
Happy Birthday to you,
Happy Birthday to you,
Happy Birthday, dear [User’s name]
Happy Birthday to you!
Note: this function does not return a value.
After the function is defined, your code should:
2. Ask the user’s name
3. Call the function defined in step 1 using the user’s response as an argument.
Part A Example:
What is your name?
>>Mohandas
Happy Birthday to you,
Happy Birthday to you,
Happy Birthday, dear Mohandas
Happy Birthday to you!
Part B
This block of code will calculate the future value of a loan where the principle is $5,000, the interest rate
is %7.9, the term of the loan is 5 years, and will compound 365 times per year:
#Should be parameters
p = ‘$5,000’ #Principle
r = ‘%7.9’ #Annual Interest Rate
t = 5 #Term of the loan
n = 365 #Compounding per year
#Should be part of Function Definition
pFloat = float(p.replace(‘$’, ”).replace(‘,’, ”))
rFloat = float(r.replace(‘%’, ”))*.01
a = pFloat*(1 + rFloat/n)**(n*t)
After the code runs, the variable ‘a’ will equal the future value of the loan. Note that p and r need to be
string datatypes because they contain the symbols $ and %.
You need to convert this block of code into a function so that it can process many loans, not just when p
= $5,00, r = %7.9, t = 5, and n = 365.
Your code must:
1. Define a function that accepts arguments for the principle, annual interest rate, term, and how
many times the loan will compound per year;
2. Because the number of times a loan compounds per year is often 365, that parameter should
have a default of 365;
3. The function must return the future value (not print it).
After you have defined this function:
4. You need to call the function and print the returned value for three different loans:
Loan 1: $5,000 principle, %7.9 interest rate, and 5 year term
Loan 2: $12,000 principle, %3.2 interest rate, and 10 year term
Loan 2: $1,700,000 principle, %4.8 interest rate, 30 year term, compounding 4 times per
year
Part B Example:
7421.603745452343
16525.301376990596
7113943.66708043
[You can also compare the results of your function to an online future value calculator, such as this one]