Python Forum
My code is giving my an output of zero, no matter what value I input
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
#1
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
Reply
#2
In line 11, you're reusing your first point instead of the second. So both points are identical.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  data input while debugging causes unwanted code completion fred1232 2 2,688 Sep-14-2025, 03:32 PM
Last Post: deanhystad
  interactive process for input and output maiya 1 2,300 Mar-27-2025, 08:40 AM
Last Post: Gribouillis
Question [SOLVED] Same input different output antarling 2 1,553 Oct-25-2024, 11:28 PM
Last Post: antarling
  problem in output of a snippet code akbarza 2 1,990 Feb-28-2024, 07:15 PM
Last Post: deanhystad
  No matter what I do I get back "List indices must be integers or slices, not list" Radical 4 3,507 Sep-24-2023, 05:03 AM
Last Post: deanhystad
Question in this code, I input Key_word, it can not find although all data was exact Help me! duchien04x4 3 2,892 Aug-31-2023, 05:36 PM
Last Post: deanhystad
  output provide the filename along with the input file processed. arjunaram 1 2,029 Apr-13-2023, 08:15 PM
Last Post: menator01
  Compiles Python code with no error but giving out no output - what's wrong with it? pythonflea 6 4,446 Mar-27-2023, 07:38 AM
Last Post: buran
  I cannot able to see output of this code ted 1 1,732 Feb-22-2023, 09:43 PM
Last Post: deanhystad
  Code won't break While loop or go back to the input? MrKnd94 2 2,806 Oct-26-2022, 10:10 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020