python 3.x - is inputted point within the rectangle centered on the (0,0) axis -


trying write simple python program determine if 2 points (x, y) input user fall within rectangle centered on (0,0) axis width of 10 , height of 5.

here am.

x = eval(input("enter x point : ")) y = eval(input("enter y point : "))   if  x <= 10.0 / 2:     if y <= 5.0 / 2:         print("point (" + str(x) + ", " + str(y) + ") in rectangle") else:     print("point (" + str(x) + ", " + str(y) + ") not in rectangle") 

this wont work on negative side. there math function needing, can't figure out one.

i have added distance = math.sqrt (( x * x ) + ( y * y )) , changed ifs distance instead of x , y. confused.

width = 10 height = 5 x_center = 0 y_center = 0  x_str = input("enter x point: ") y_str = input("enter y point: ") x = float(x_str) y = float(y_str)  is_in = true if not (x_center - width/2 <= x <= x_center + width/2):     is_in = false if not (y_center - height/2 <= y <= y_center + height/2):     is_in = false if is_in:     statement = "is" else:     statement = "is not" print("point (%s, %s) %s in rectangle." % (x_str, y_str, statement)) 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -