Ask your own question, for FREE!
MIT 6.189 A Gentle Introduction to Programming Using Python (OCW) 16 Online
OpenStudy (anonymous):

MIT 6.189 Math Module HW 2.3

OpenStudy (anonymous):

I was able to get working answers to the math module homework, but I worry I missed some of the spirit of the exercise. For a few of the multadds, I ended up just multiplying by 1, e.g. angle_test = multadd(1,math.sin(math.pi/4),math.cos(math.pi/4)/2) Here's a link to 2.3 in its entirety. Would love some feedback. https://gist.github.com/TomDeBeauchamp/5855418

OpenStudy (e.mccormick):

I didn't see import math there....

OpenStudy (anonymous):

good point. I cut this from the bigger .py, but left the import math behind. Just updated.

OpenStudy (espex):

What was your intent with lines like this: print (multadd(6,3,3), 6*3+3)?

OpenStudy (espex):

Just checking your function?

OpenStudy (e.mccormick):

yah, the assignement says to do several tests of it.

OpenStudy (e.mccormick):

1. Write a function multadd that takes three parameters, a, b and c. Test your function well before moving on.

OpenStudy (espex):

Well I would have expected a print similar to: print (multadd(6,3,3), "= 6*3+3")

OpenStudy (anonymous):

That would have been a better way to do it eSpeX, definitely, though the intent was the same. I was just checking the function.

OpenStudy (espex):

Looks pretty good to me.

OpenStudy (e.mccormick):

If everything is working correctly, your output should look like: sin(pi/4) + cos(pi/4)/2 is: 1.06066017178 ceiling(276/19) + 2 log_7(12) is: 17.5539788165 And for Yikes! Try x=5 as a test; your answer should look like: yikes(5) is 1.0303150673. Did you get the expected returns?

OpenStudy (espex):

>>> 21 =6*3+3 9 9 -9 -9 -39 -39 1.0606601717798212 17.55397881653925 yikes(5) = 1.0303150673048738 >>>

OpenStudy (anonymous):

I did get the expected returns, so maybe there's nothing to be worried about (though, maybe there are some formatting issues with the output).

OpenStudy (anonymous):

Really, my confusion, or concern was with the use of multadd: e.g. angle_test = multadd(1,math.sin(math.pi/4),math.cos(math.pi/4)/2) There's nothing wrong with multiplying by 1 to get the answer, I just wondered if the problem had some other intent. We create a function to do a*b+c, it seemed like the answer would exploit each of those variables. Could be overthinking it.

OpenStudy (e.mccormick):

angle_test = multadd(math.cos(math.pi/4),1/2.0,math.sin(math.pi/4))

OpenStudy (espex):

The intent was to get you building a compound argument using multiple functions.

OpenStudy (anonymous):

Got it. Thanks for the feedback!

OpenStudy (anonymous):

e., that's it! More complex, just like I wanted :)

OpenStudy (e.mccormick):

You can do the same thing with: ceiling_test = multadd(1,math.ceil(276/19.0),2*math.log(12,7)) ceiling_test = multadd(math.log(12,7),2,math.ceil(276/19.0))

OpenStudy (e.mccormick):

Actually, less complex. I just used order of operations to do the addition on the left rather than the right. The multiplication will fire first no matter what. So rather than explicitly doing the multiplication in what I pass, I implicitly do it through the function by changing the order.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!