In: Computer Science
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
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.