Python Forum
My code is giving my an output of zero, no matter what value I input - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: My code is giving my an output of zero, no matter what value I input (/thread-28008.html)



My code is giving my an output of zero, no matter what value I input - PiyushBanarjee - Jul-01-2020

Hi there, I will be very thankful to you if you can help me. I had written the following code to find the distance between two points on a graph through the distance formula, which is a topic of coordinate geometry just in case if you want to know more about it. (I am 14 years old so please don't be too frustrated about the poor quality of my code, sorry).
# The code was supposed to give the distance between two points on a graph through the distance formula
# but whatever input I give, it always gives me an output of 0
# the Distance formula is d=√((x_2-x_1)²+(y_2-y_1)²) where (x_1, y_1) and (x_2, y_2) are points on graph
firstP = input("Enter the coordinates of first point in form x,y -> ")
firstC = firstP.split(",")

x1 = int(firstC[0])
y1 = int(firstC[1])

secondP = input("Enter the coordinates of second point in form x,y -> ")
secondC = firstP.split(",")
x2 = int(secondC[0])
y2 = int(secondC[1])
print((((x1-x2)**2) + ((y1 - y2)**2))**(1/2))
Output:
C:\Users\admin\AppData\Local\Programs\Python\Python37\python.exe "C:/Users/admin/PycharmProjects/Maths Projects/Prototype1.py" Enter the coordinates of first point in form x,y -> 1,2 Enter the coordinates of second point in form x,y -> 2,4 0.0 Process finished with exit code 0



RE: My code is giving my an output of zero, no matter what value I input - bowlofred - Jul-01-2020

In line 11, you're reusing your first point instead of the second. So both points are identical.