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

Here are the functions that your module should include: 1. A money function that

ID: 3567679 • Letter: H

Question

Here are the functions that your module should include: 1. A money function that takes 1 parameter (a string) and returns a 2-tapie. The string is a monetary amount (e.g., ?1.50?) which should contain a decimal point, and exactly 2 digits to the right of the decimal. If this function is passed a string in the wrong format, an exception should be raised. 2. An add function which takes 2 parameters, both of which are 2-tuples, and which returns a 2-tapie that represents the sum of the parameters. 3. An interest function. This function should take 2 parameters: a 2-tuple, and an interest rate in the form of a floating point number (e.g., .02 represents a 2% interest rate). The function should return a monetary amount (in the form of a 2-tuple) which equals the monetary amount times the interest rate plus 1. 4. A tostring function, which is passed a monetary amount (a 2-tuple) and which returns a string in the form ?dci. cc? (exactly 2 digits to the right of the decimal). Here is an example illustrating how your module should work once it is completed: For 2 points extra credit, write a function called input Money. It is passed a prompt as its only parameter. It should prompt the user to enter a monetary amount, and returns a 2-tapie representing the amount. If the input is not in the correct format, it print a message to that effect and ask the user to re-enter. prompt and ask the user to re-enter.

Explanation / Answer

def money(value):

decIndex = value.find('.')
try:
if len(value[decIndex+1:])>2:
raise Exception('Number of decimal after decimal point should be 2')
except Exception as inst:
x = inst.args
print x
return
  
return tuple((int(value[0:decIndex]),int(value[decIndex+1:])))

def add(first,second):
if first[1]+second[1]>=100:
a = first[0]+second[0]+1
b = (first[1]+second[1])*.01
c = money(str(b))

return tuple((a,c[1]))
else:
return tuple(((first[0]+second[0]),(first[1]+second[1])))

def interest(value,int_):
value = (value[0]+value[1])*int_+value[0]+value[1]

decIndex= (str(value)).find('.')
value = str(value)
return tuple((int(value[0:decIndex]),int(value[decIndex+1:1])))
  

def toString(value):
if len(str(value[1]))==2:
a = value[1]*.01
else:
a = value[1]*.1

return str(value[0]+a)

print interest((30,0),.05)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote