I'm having trouble on the 2.3 Math Module exercise. Maybe it's because I'm not great at math, but I have no idea what the angle_test or ceiling_test functions should look like. Any help?
Just took a quick look at problem statement. angle_test and ceiling_test are not functions. They are just variables being assigned values. Looks like part 2 is only there to get some practice using the functions imported with the math module. The only one that should give you pause is the base 7 log. Normally, we think in terms of base 10 log or base e log. But the documents for the log function describes how to specify the base (default base is e, the natural log function).
I'm struggling with this too because I don't understand the instruction for 2.3 part 2:"Underneath your function definition, computer the following values using multadd and print out the result." I'm just not sure what's being asked for. You can get the output they want with this statement, but it doesn't use your multadd function: print "sin(pi/4) + cos(pi/4)/2 is: ", (math.sin(math.pi/4)+ math.cos(math.pi/4)/2)
You can use your multadd function. It looks rather contrived, though. I guess you could try it without using multadd and then repeat it forcing the use of multadd. angle_test = multadd( 0.5, cos(...), sin(...) and similarly ceiling_test = multadd( 2.0, log(...), ceil(...)) I, personally, don't see much value in using multadd here, but I'll go through the exercise just to confirm that my multadd function produces the correct result.
Okay, so I get: angle_test= multadd(math.sin(math.pi/4), 0.5, math.sin(math.pi/4)) print "sin(pi/4) + cos(pi/4)/2 is: \n", angle_test Seems a long way to go. I guess I was overthinking it, thanks. Oddly the ceiling function comes out at 16.55etc rather than 17.55etc. as in their example.
Thanks, I've gotten the angle_test one to work, just trying to get syntax correct for the ceiling_test, but I'm getting there.
So my answer isn't right, but it's at least working. I understand the concepts so I'm moving on :)
exchaoordo, I had the same result - 16.55... instead of 17.55... I realised that being exactly 1.0 off the right answer must have had something to do with the ceiling function rounding up, combined with the truncation that happens when you divide with integers rather than floats. Changing one of my integers (19) to a float (19.0) gave me the correct answer: print multadd(math.log(12,7), 2.0, math.ceil(276/19)) >>>16.5539788165 print multadd(math.log(12,7), 2.0, math.ceil(276/19.0)) >>>17.5539788165
Join our real-time social learning platform and learn together with your friends!