The error in finding the distance between the two points is invalid syntax.

Asked 2 years ago, Updated 2 years ago, 15 views

Two points (cospi/3, sinpi/3) and (-exp(2), log(10)
I wrote the following code to find the distance.

import path

def distance (x1, y1, x2, y2):
  return((x2-x1)**2+(y2-y1)**2)**0.5

print(((math.cos(math.pi/3)),(math.sin(math.pi/3)),(-math.exp(2)),(math.log(10)).

Then the error says "invalid synctax" and it doesn't print well.

When I displayed the four values using the path in print, it was calculated well, so I don't think it was a mistake in that part.

Could you please let me know where I need to correct the code to work well?

Thank you for your cooperation.

python

2022-09-30 16:31

1 Answers

This may simply be because the last . of each parameter is unnecessary and the last ) is missing.

It should work by doing the following:

print(distance((math.cos(math.pi/3)), (math.sin(math.pi/3)), (-math.exp(2), (math.log(10))))


2022-09-30 16:31

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.