Home > Enterprise >  The program is only printing one of my statements from the loop
The program is only printing one of my statements from the loop

Time:11-21

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

CodePudding user response:

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.

CodePudding user response:

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.

  • Related