Language : Python 3 Write a function that takes as input five numbers ( 5 input
ID: 672929 • Letter: L
Question
Language : Python 3
Write a function that takes as input five numbers ( 5 input parameters). The first two input parameters are numbers that represent the x and y coordinates of the bottom left corner of a square.
Write a function called in-or-out-square that takes as input five numbers (i.e. the function has 5 input parameters). The first two input parameters are numbers that represent the x and y coordinates of the bottom left corner of a square. The third number represents the length of the side of thesquare. The fourth and fifth number represent the x and y coordinates of some query point.You may assume that all 5 parameters are numbers. However if the side length is a negative number, the function should return the string "invalid side length".therwise, if the side length is positive, your function should test if the given query point is inside of the given square. A point on the boundary of a square is considered to be inside the square. If the query point is inside the given square, the function should return one string containing nicely formatted sentence stating the results. See the|Testing your function:Explanation / Answer
#!/usr/bin/python
def in_or_out_square(x1,y1,side,x2,y2): #Function definition.
if side < 0: #If side is less than 0.
print("Invalid side length") #Display message.
else: #If side is greater than or equal to 0.
if x2 >= x1 and x2 <= x1+side and y2 >= y1 and y2 <= y1+side: #If the query point is inside the square.
print "The given query point (",x2,", ",y2,") is inside of the square." #Display message.
else: #If the query point is outside the square.
print "The given query point (",x2,", ",y2,") is outside of the square." #Display message.
in_or_out_square(2.5,1,1,3,1.5)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.