Question

In: Computer Science

1. Write a function named computeInterest that computes the amount # of interest on a given...

1. Write a function named computeInterest that computes the amount

# of interest on a given amount of money. The function should accept

# the amount of starting money (deposit) and the interest rate (rate)

# and return total amount of money in account after the interest is added.

# Just use a basic interest calculations. For example, for a deposit of

# 100 and a rate of 0.045 your function should return 104.5.

# You must have exception handling. If a string value is sent to the

# function instead of a number, print "Use only numeric values".

#

# Finally, add MULTIPLE doctest tests to the docstring below to test your

# computeInterest method using a number different values

def computeInterest(deposit, rate):

'''

Compute and return the total value of a deposit after applying a simple

interest amount.

TESTS BELOW:

PYTHON

Solutions

Expert Solution

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Here a new python program with name "main.py" is created, which contains following code.

main.py :

#Python program to compute interest
#function
def computeInterest(deposit,rate):
#calculate interest amount
interest=deposit*rate
#return amount with interest
return deposit+interest
  
#Exception handling
try:
#asking user to enter amount
amount=int(input("Enter Amount : "))
#asking user to enter rate
rate=float(input("Enter Rate of Interest : "))
#calling function computeInterest() sending amount
amountInterest=computeInterest(amount,rate)
#display amount
print("Amount after interest : ",amountInterest)
except ValueError:
#display exception
print("Enter only numeric values")

Screen for Indentation Purpose :

======================================================

Output : Compile and Run above program to get the screens as shown below

Screen 1 :Screen asking to enter amount

Screen 2:Screen if amount is string

Screen 3:Screen if rate is non numeric

Screen 4:Screen showing total amount after interest

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.


Related Solutions

Write a Java method that computes the future investment value at a given interest rate for...
Write a Java method that computes the future investment value at a given interest rate for a specified number of years. Your method should return the future investment value after calculation. The future investment is determined using the formula below:     futureInvestmentValue = investmentAmount * (1+monthlyInterestRate)numberOfYears*12 You can use the following method header: public static double futureInvestmentValue (double investmentAmount, double monthlyInterestRate, int years);
C++ Write a recursive function that computes and returns the product of the first n >=1...
C++ Write a recursive function that computes and returns the product of the first n >=1 real numbers in an array.
Write code that classifies a given amount of money (which you store in a variable named...
Write code that classifies a given amount of money (which you store in a variable named amount), specified in cents, as greater monetary units. Your code lists the monetary equivalent in dollars (100 ct), quarters (25 ct), dimes (10 ct), nickels (5 ct), and pennies (1 ct). Your program should report the maximum number of dollars that fit in the amount, then the maximum number of quarters that fit in the remainder after you subtract the dollars, then the maximum...
Write code that classifies a given amount of money (which you store in a variable named...
Write code that classifies a given amount of money (which you store in a variable named amount), specified in cents, as greater monetary units. Your code lists the monetary equivalent in dollars (100 ct), quarters (25 ct), dimes (10 ct), nickels (5 ct), and pennies (1 ct). Your program should report the maximum number of dollars that fit in the amount, then the maximum number of quarters that fit in the remainder after you subtract the dollars, then the maximum...
Write the following easy Python functions: 1) Write the function named roundDollars(). The function has one...
Write the following easy Python functions: 1) Write the function named roundDollars(). The function has one input, a String named amountStr which consists of a dollar-formatted amount, such as "$ 1,256.86". The returned value is an int representing the number of rounded "dollars" in the amount, (1257 in the sample shown here). You will need to scrub, format and parse the input, then use arithmetic to determine how many rounded dollars the amount contains. roundDollars("$ 1,256.86") → 1257 roundDollars("$ 0.42")...
In the space provided below write a C ++ program that computes the total amount of...
In the space provided below write a C ++ program that computes the total amount of money you are depositing in your bank account. Your program does this by asking you to first enter the number and amount of each check you are depositing, and then it asks you to enter the type of cash bills being deposited and how many of each type, also the types of coins being deposited, and the number of each coin type.
PYTHON: Write a recursive function named linear_search that searches a list to find a given element....
PYTHON: Write a recursive function named linear_search that searches a list to find a given element. If the element is in the list, the function returns the index of the first instance of the element, otherwise it returns -1000. Sample Output >> linear_search(72, [10, 32, 83, 2, 72, 100, 32]) 4 >> linear_search(32, [10, 32, 83, 2, 72, 100, 32]) 1 >> linear_search(0, [10, 32, 83, 2, 72, 100, 32]) -1000 >> linear_search('a', ['c', 'a', 'l', 'i', 'f', 'o', 'r',...
Write a c++ function named multi_table to print out multiplication table for a given number of...
Write a c++ function named multi_table to print out multiplication table for a given number of rows and columns. Your program should print a header row and a header column to represent each row and column number. For example your function call multi_table(4, 4) would print below to the command line: 1 | 1 2 3 4 _________ 2 | 2 4 6 8 3 | 3 6 9 12 4 | 4 8 12 16 Test your function in...
Given an integer named area which represents the area of a rectangle, write a function minPerimeter...
Given an integer named area which represents the area of a rectangle, write a function minPerimeter that calculates the minimum possible perimeter of the given rectangle, and prints the perimeter and the side lengths needed to achieve that minimum. The length of the sides of the rectangle are integer numbers. For example, given the integer area = 30, possible perimeters and side-lengths are: (1, 30), with a perimeter of 62 (2, 15), with a perimeter of 34 (3, 10), with...
Given an integer named area which represents the area of a rectangle, write a function minPerimeter...
Given an integer named area which represents the area of a rectangle, write a function minPerimeter that calculates the minimum possible perimeter of the given rectangle, and prints the perimeter and the side lengths needed to achieve that minimum. The length of the sides of the rectangle are integer numbers. For example, given the integer area = 30, possible perimeters and side-lengths are: (1, 30), with a perimeter of 62 (2, 15), with a perimeter of 34 (3, 10), with...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT