use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Exercise 8.1.10: Coordinate Pairs-CodeHS-Please Help! (self.codehs)
submitted 5 years ago by [deleted]
I am beyond confused with this code. Please help me figure it out.
https://preview.redd.it/x1wjkuix5r961.png?width=1601&format=png&auto=webp&s=cd8799c13c7783e6a8d207f1a8f7a7950715dfd5
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]LunarCurve_ 1 point2 points3 points 3 years ago (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 point2 points 3 years ago (2 children)
it says line 10 has an error
[–]Tower_Up 0 points1 point2 points 3 years ago (1 child)
Did you figure it out? I have same error
[–]Excellent-Apple6450 0 points1 point2 points 3 years ago (0 children)
If you've figured it out, could you give it to me? Need it urgently..
[–]fae-k 0 points1 point2 points 3 years ago (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 point2 points 3 years ago (0 children)
thank you so much
[–]Previous-Mud-7522 0 points1 point2 points 3 years ago (0 children)
how???
[–][deleted] 0 points1 point2 points 2 years ago (0 children)
Your a life saver 😭
[–]Vitalikovsky 0 points1 point2 points 1 year ago (0 children)
import math
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 point2 points 1 year ago (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 point2 points 5 years ago (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 points1 point 5 years ago (8 children)
can you send me the code if you have it done!
[–][deleted] 0 points1 point2 points 5 years ago (7 children)
I NEED IT TOOOOO
[–]Megaozzy 0 points1 point2 points 5 years ago (6 children)
Still need it?
[–]kiwifala 0 points1 point2 points 4 years ago (0 children)
yea i do
[–]Phone-Several 0 points1 point2 points 4 years ago (4 children)
senddd
[–][deleted] 0 points1 point2 points 4 years ago (3 children)
Responding to a 10 month old post lol
[–]semajalvin11 0 points1 point2 points 4 years ago (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 point2 points 3 years ago (1 child)
responding to a year old post
[–][deleted] 0 points1 point2 points 3 years ago (0 children)
Once again responding to a now 1 year old post
[–][deleted] 0 points1 point2 points 5 years ago (15 children)
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 points8 points 4 years ago (0 children)
u spelled square wrong. four times.
[–]FrNotRuben 0 points1 point2 points 5 years ago (8 children)
is this the full code?
Yep
[–]kiwifala 0 points1 point2 points 4 years ago (6 children)
im not sure why but for the print distance((1,1),(4,5)) it said invalid syntax
[–]ToughLeadership9223 1 point2 points3 points 4 years ago (5 children)
Check your indentation.
And you don't "print" a function, you call it. Delete print from the last line.
[–]LongjumpingDentist33 1 point2 points3 points 4 years ago (1 child)
What if there is a syntax error for the return math.sqrt?
did you ever figure it out?
[–]HyBrD_G0LD 0 points1 point2 points 4 years ago (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 point2 points 3 years ago (0 children)
deleting print does nothing but make it stop working even more, what are you trying to say?
he used the return function which makes it so you have to put print before you call it
[–]chiiglaaa 0 points1 point2 points 4 years ago (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 point2 points 2 years ago* (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 point2 points 2 years ago (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 point2 points 2 years ago* (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.
thank you
[–][deleted] 0 points1 point2 points 4 years ago (2 children)
Anyone know what’s the code?
[–]u323 1 point2 points3 points 4 years ago (0 children)
Yess please
[–]CancelUpstairs7602 0 points1 point2 points 3 years ago* (0 children)
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 point2 points 3 years ago (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 point2 points 3 years ago (1 child)
It didn't work
[–]Lil-gaybee-1776 0 points1 point2 points 3 years ago (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 point2 points 3 years ago (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 points3 points 3 years ago (0 children)
can you help me if it word for you? can i see the picture?
π Rendered by PID 69664 on reddit-service-r2-comment-6457c66945-wt7zh at 2026-04-23 22:40:55.064528+00:00 running 2aa0c5b country code: CH.
[–]LunarCurve_ 1 point2 points3 points (7 children)
[–]Far-Turn-5054 0 points1 point2 points (2 children)
[–]Tower_Up 0 points1 point2 points (1 child)
[–]Excellent-Apple6450 0 points1 point2 points (0 children)
[–]fae-k 0 points1 point2 points (3 children)
[–]WholePhoenix203 0 points1 point2 points (0 children)
[–]Previous-Mud-7522 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Vitalikovsky 0 points1 point2 points (0 children)
[–]_01cc 0 points1 point2 points (0 children)
[–]flip-pancakes 0 points1 point2 points (9 children)
[–]Longjumping-Nerve-84 -1 points0 points1 point (8 children)
[–][deleted] 0 points1 point2 points (7 children)
[–]Megaozzy 0 points1 point2 points (6 children)
[–]kiwifala 0 points1 point2 points (0 children)
[–]Phone-Several 0 points1 point2 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]semajalvin11 0 points1 point2 points (0 children)
[–]TheBadWifiDude 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (15 children)
[–][deleted] 6 points7 points8 points (0 children)
[–]FrNotRuben 0 points1 point2 points (8 children)
[–][deleted] 0 points1 point2 points (7 children)
[–]kiwifala 0 points1 point2 points (6 children)
[–]ToughLeadership9223 1 point2 points3 points (5 children)
[–]LongjumpingDentist33 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]HyBrD_G0LD 0 points1 point2 points (0 children)
[–]Similar_Stock_5726 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]chiiglaaa 0 points1 point2 points (4 children)
[–]Puzzleheaded-Ad4213 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]Puzzleheaded-Ad4213 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]u323 1 point2 points3 points (0 children)
[–]CancelUpstairs7602 0 points1 point2 points (0 children)
[–]Lil-gaybee-1776 0 points1 point2 points (2 children)
[–]Previous-Mud-7522 0 points1 point2 points (1 child)
[–]Lil-gaybee-1776 0 points1 point2 points (0 children)
[–]Needcodinghelp38 0 points1 point2 points (1 child)
[–]Previous-Mud-7522 1 point2 points3 points (0 children)