-1

I'm not sure why my code isn't fully printing. It isn't printing the quadrants.

Here are my instructions:

  • You are writing a program that checks if a point (a,b) is inside a circle of radius R that is centered on the point (c,d).

-a,b,c,d,R are all integers entered from the keyboard -Do not allow negative R values to be entered -The output can be a simple statement indicating if the (a,b) point is “In the Circle”, “Out of the Circle”, “On the Circle” -Also output the Quadrant (I,II,III, IV) that the point (a,b) is located in. If the point happens to be on either the x or y axis, then output which axis it is on. -Your program is to continue forever until a radius of 0 is entered.

Note: If you are wondering about how to compute the distance between 2 points…. use the Pythagorean Theorem

Here's my code:

import math
while True:
    a= int(input("Please enter the value of a:"))
    b= int(input("Please enter the value of b:"))
    c= int(input("Please enter the value of c:"))
    d= int(input("Please enter the value of d:"))
    r= int(input("Please enter the value of R:"))

#XI= c, Y1= d .... X2= a, Y2= b
    xs= ((a)-c)**2
    ys= ((b)-d)**2
    together= xs+ys
    distance= math.sqrt(together)

   if distance > r:
      print("Out of the circle")

   if distance < r:
      print("In the circle")

   if distance == r:
      print("On the circle")

#If the point lies on the x or y axis:
   if a == 0:
      print("On y axis")
   if b == 0:
      print("On x axis")
        
#Quadrant I:
   if a < r < 0 and b < r < 0:
      print("Quadrant I")
    
#Quadrant II:
   if -a < r < 0 and b < r < 0:
      print("Quadrant II")

#Quadrant III:
   if -a < r < 0 and -b < r < 0:
      print("Quadrant III")

#Quadrant IV:
   if a < r < 0 and -b < r < 0:
       print("Quadrant IV")

   if r == -r or r == 0:
       break
coder J
  • 1
  • 2
  • Yes, all of my lines are indented the same – coder J Nov 20 '22 at 16:09
  • What is r doing in the quadrant determination tests ? r < 0 should be false, which explains why the tests never pass; another thing: you're supposed not to allow negative values of r to be entered; this should be done when r is input ( and r == -r is not a good test...). – Swifty Nov 20 '22 at 16:50
  • 1
    [How to step through Python code to help debug issues?](https://stackoverflow.com/questions/4929251/how-to-step-through-python-code-to-help-debug-issues) If you are using an IDE **now** is a good time to learn its debugging features Or the built-in [Python debugger](https://docs.python.org/3/library/pdb.html). Printing *stuff* at strategic points in your program can help you trace what is or isn't happening. [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) – wwii Nov 20 '22 at 17:02
  • Please fix the indentation in your code. `if distance > r: IndentationError: unindent does not match any outer indentation level` – wwii Nov 20 '22 at 17:05

2 Answers2

0

Your code has a while loop that never exits, so what comes after it is never executed.

You should ident everything after distance= math.sqrt(together) into the loop as well.

LITzman
  • 730
  • 1
  • 16
  • I indented everything at the same spot in python but it's still not working – coder J Nov 20 '22 at 16:07
  • 1
    If by "not working" you mean that you don't see the print statements that you expect to see than perhaps the logic you used in the conditions is incorrect – LITzman Nov 20 '22 at 16:09
0

You haven't told the code when to stop receiving input so it just awaits your input over and over again. Using a while loop is easy to cause infinite loops, so you must be careful about when to stop. You can set a value that if you input the value, the loop breaks and continue to run.

Katono
  • 28
  • 4
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 22 '22 at 15:29