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
  problem in output of a snippet code akbarza 2 300 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 1,091 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 971 Aug-31-2023, 05:36 PM
Last Post: deanhystad
  output provide the filename along with the input file processed. arjunaram 1 903 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 1,468 Mar-27-2023, 07:38 AM
Last Post: buran
  I cannot able to see output of this code ted 1 715 Feb-22-2023, 09:43 PM
Last Post: deanhystad
  Code won't break While loop or go back to the input? MrKnd94 2 906 Oct-26-2022, 10:10 AM
Last Post: Larz60+
  Help Switching between keyboard/Mic input in my code Extra 1 1,044 Aug-28-2022, 10:16 PM
Last Post: deanhystad
  why I dont get any output from this code William369 2 1,084 Jun-23-2022, 09:18 PM
Last Post: William369
  How can I organize my code according to output that I want ilknurg 1 1,137 Mar-11-2022, 09:24 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

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