Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 My code is giving my an output of zero, no matter what value I input
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))
C:\Users\admin\AppData\Local\Programs\Python\Python37\python.exe "C:/Users/admin/PycharmProjects/Maths Projects/" 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
In line 11, you're reusing your first point instead of the second. So both points are identical.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Why this code not getting desired output ? MDRI 1 316 Jul-02-2020, 01:21 AM
Last Post: MDRI
  Hi, I need help with defining user's input and applying it to code. jlmorenoc 2 261 Jun-24-2020, 02:10 PM
Last Post: pyzyx3qwerty
  Help me input the Rawdata file so that it can output DataErrorFile and ValidData.txt Halozeus 6 321 May-01-2020, 07:11 AM
Last Post: bowlofred
  ınput-output HELP! bwdu 1 219 Apr-18-2020, 09:53 PM
Last Post: deanhystad
  Input() function not working in VS Code darpInd 7 501 Feb-17-2020, 03:28 PM
Last Post: snippsat
  Help w/ Max/Min User Input Code ThatGreatState 2 320 Nov-26-2019, 02:52 PM
Last Post: ichabod801
  Output of Python code hemal07yc 5 465 Sep-13-2019, 11:33 AM
Last Post: perfringo
  Four text files input combinations into an output file mhyga 2 581 Jul-28-2019, 06:52 PM
Last Post: ThomasL
  A question about subprocess taking input from command line and returning output! Aurimas 8 1,058 May-15-2019, 04:02 PM
Last Post: Aurimas
  Output not following rules set in code. Escribblings 4 569 Apr-24-2019, 12:49 PM
Last Post: Escribblings

Forum Jump:

Users browsing this thread: 1 Guest(s)