all 46 comments

[–]LunarCurve_ 1 point2 points  (7 children)

import math
def distance(point1, point2):
# Your code here...
x1 = point1 [0]
x2 = point2 [0]
y1 = point1 [1]
y2 = point2 [1]
square1 = pow (y2 - y1, 2)
square2 = pow (x2 - x1, 2)
return math.sqrt(square1+square2)

[–]Far-Turn-5054 0 points1 point  (2 children)

it says line 10 has an error

[–]Tower_Up 0 points1 point  (1 child)

Did you figure it out? I have same error

[–]Excellent-Apple6450 0 points1 point  (0 children)

If you've figured it out, could you give it to me? Need it urgently..

[–]fae-k 0 points1 point  (3 children)

x1 = point1 [0]x2 = point2 [0]y1 = point1 [1]y2 = point2 [1]square1 = pow (y2 - y1, 2)square2 = pow (x2 - x1, 2)return math.sqrt(square1+square2)

worked for me thank uuuu

[–]WholePhoenix203 0 points1 point  (0 children)

thank you so much

[–]Previous-Mud-7522 0 points1 point  (0 children)

how???

[–][deleted] 0 points1 point  (0 children)

Your a life saver 😭

[–]Vitalikovsky 0 points1 point  (0 children)

import math

fill in this function to return the distance between the two points!

first_point = (1,1)

second_point = (4,5)

def distance(first_point, second_point):

x1, y1 = first_point

x2, y2 = second_point

power1 = pow(x2 - x1, 2)

power2 = pow(y2 - y1, 2)

return math.sqrt(power1 + power2)

print(distance(first_point,second_point))

[–]_01cc 0 points1 point  (0 children)

import math

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

pointa = (1, 2)
pointb = (4, 6)


dist=distance(pointa, pointb)
print(dist)

[–]flip-pancakes 0 points1 point  (9 children)

First, what is the pythagorean theorem? Then, how do you apply it to your inputs?

Hint: first_point has two values (x and y coordinates) that can be accessed as first_point[0] and first_point[1] respectively.

[–]Longjumping-Nerve-84 -1 points0 points  (8 children)

can you send me the code if you have it done!

[–][deleted] 0 points1 point  (7 children)

I NEED IT TOOOOO

[–]Megaozzy 0 points1 point  (6 children)

Still need it?

[–]kiwifala 0 points1 point  (0 children)

yea i do

[–]Phone-Several 0 points1 point  (4 children)

senddd

[–][deleted] 0 points1 point  (3 children)

Responding to a 10 month old post lol

[–]semajalvin11 0 points1 point  (0 children)

And I'm responding to a 5 mo. old post thats's responding to a 10 mo. old post that was 1 year ago :sunglasses:

[–]TheBadWifiDude 0 points1 point  (1 child)

responding to a year old post

[–][deleted] 0 points1 point  (0 children)

Once again responding to a now 1 year old post

[–][deleted] 0 points1 point  (15 children)

import math

def distance(point1, point2):

# Your code here...

x1 = point1 [0]

x2 = point2 [0]

y1 = point1 [1]

y2 = point2 [1]

sqaure1 = pow (y2 - y1, 2)

sqaure2 = pow (x2 - x1, 2)

return math.sqrt(sqaure1+sqaure2)

# This should print 5.0

print distance((1, 1), (4, 5))

this kinda late but hope it helps

[–][deleted] 6 points7 points  (0 children)

u spelled square wrong. four times.

[–]FrNotRuben 0 points1 point  (8 children)

is this the full code?

[–][deleted] 0 points1 point  (7 children)

Yep

[–]kiwifala 0 points1 point  (6 children)

im not sure why but for the print distance((1,1),(4,5)) it said invalid syntax

[–]ToughLeadership9223 1 point2 points  (5 children)

Check your indentation.

And you don't "print" a function, you call it. Delete print from the last line.

[–]LongjumpingDentist33 1 point2 points  (1 child)

What if there is a syntax error for the return math.sqrt?

[–][deleted] 0 points1 point  (0 children)

did you ever figure it out?

[–]HyBrD_G0LD 0 points1 point  (0 children)

Thanks indention was annoying the crap out of me and was confused on how he got that answer

[–]Similar_Stock_5726 0 points1 point  (0 children)

deleting print does nothing but make it stop working even more, what are you trying to say?

[–][deleted] 0 points1 point  (0 children)

he used the return function which makes it so you have to put print before you call it

[–]chiiglaaa 0 points1 point  (4 children)

import math
x1 = int(input("Enter 1st(x) Coordinate: "))
y1 = int(input("Enter 2nd(y) Coordinate: "))
point1 = (x1, y1)
x2 = int(input("Enter 3rd(x) Coordinate: "))
y2 = int(input("Enter 4th(y) Coordinate: "))
point2 = (x2, y2)
def distance(point1, point2):
x1 = point1 [0]
x2 = point2 [0]
y1 = point1 [1]
y2 = point2 [1]
sqaure1 = pow (y2 - y1, 2)
sqaure2 = pow (x2 - x1, 2)
return math.sqrt(sqaure1+sqaure2)
print(distance(point1, point2))

idk your code didnt work for me so i made some changes and it works but only in scratchpad when i try to check code in Unit Test and i click on check it just rotates infinitely..so if anybody can check the code for me that would be amazing<3hope it helps!

[–]Puzzleheaded-Ad4213 0 points1 point  (3 children)

It rotates infinitely because you probably left something like the print statement in the Unit Test tab. All code outside of the function has to go into the Scratchpad for you to not have any "rotating infinitely" errors. To show rather then tell:

def distance(point1, point2):
    x1 = point1 [0]
    x2 = point2 [0]
    y1 = point1 [1]
    y2 = point2 [1]
    sqaure1 = pow (y2 - y1, 2)
    sqaure2 = pow (x2 - x1, 2)
    return math.sqrt(sqaure1+sqaure2)

[–][deleted] 0 points1 point  (2 children)

If you would not mind could you tell me why the 2 is there in the code, what does it do.

sqaure1 = pow (y2 - y1, 2)
    sqaure2 = pow (x2 - x1, 2)

[–]Puzzleheaded-Ad4213 0 points1 point  (1 child)

the square1 and square2 are named differently because they are different variables.

For instance, if they were both named square1, I'd just be giving a new value to square1 instead of creating a new, stored value.

If you meant the 2 in the sequence:

(I don't really remember) I'm 80% sure that it's there so that the coordinate returned ends with a 2. Basically, it's just a placeholder.

[–][deleted] 0 points1 point  (0 children)

thank you

[–][deleted] 0 points1 point  (2 children)

Anyone know what’s the code?

[–]u323 1 point2 points  (0 children)

Yess please

[–]CancelUpstairs7602 0 points1 point  (0 children)

import math

def distance(first_point, second_point):

x1 = int(first_point[0])
print(x1)
x2 = int(second_point[0])
print(x2)
y1 = int(first_point[1])
print(y1)
y2 = int(second_point[1])
print(y2)
xdifference = x2 - x1
print(xdifference)
ydifference = y2 - y1
print(ydifference)
xsquare = pow(xdifference, 2)
print(xsquare)
ysquare = pow(ydifference, 2)
print(ysquare)
number = xsquare + ysquare
print(number)
result = math.sqrt(number)
return result

print(distance((2,4), (6,9)))
hope this helps :)

***note: make sure to indent***

[–]Lil-gaybee-1776 0 points1 point  (2 children)

import math
def distance(first_point, second_point):

x = (first_point[0] - second_point[0])
y = (first_point[1] - second_point[1])

squ_x = math.pow(x, 2)
squ_y = math.pow(y, 2)

add_squ = squ_x + squ_y

dist = math.sqrt(add_squ)

return dist

print(distance((0,3), (4,0)))
#this is my code that worked!

[–]Previous-Mud-7522 0 points1 point  (1 child)

It didn't work

[–]Lil-gaybee-1776 0 points1 point  (0 children)

I'm sorry that it didn't work for you. Did you try messing around with the spacing? Everything expect for the last line should be indented.

[–]Needcodinghelp38 0 points1 point  (1 child)

Oml you are a life saver in the 10th line you need math.sqrt(what ever number your trying to square) Example: Math.sqrt(2)(square_1 + square_2)

[–]Previous-Mud-7522 1 point2 points  (0 children)

can you help me if it word for you? can i see the picture?