MOOC question Handout #2 Exercise 2.3 The task is to use the function multadd to compute the following value: angle_test = sin (π/4) + [cos(π/4)/2] This is my code: import math def multadd (a, b, c): return a * b + c print multadd ((1/2), (math.cos(math.pi/4)), math.sin(math.pi/4)) my output is: 0.707106781187 the handout says the output of sin(pi/4) + cos(pi/4)/2 is: 1.06066017178 can anyone see where I am going wrong here? Since multadd is a*b+c, in my code a=(1/2) , b = cos(pi/4) c=sin(pi/4)
remember that in python 2.x.x, 1/2 gives simple integer division, so 1/2 >> 0 your problem may be just that, in which case you need to cast at least one of those numbers as a float to obtain a float as a result, i.e. 1.0/2 >> 0.5
That was exactly it! Thanks so much
Join our real-time social learning platform and learn together with your friends!