Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help solving a problem
#1
Hi, I'm a Python novice. I have the following code, but after running it doesn't return any result, not even error code, what is the problem?

def isIn(firstCorner=(1,2), secondCorner=(3,4), point=(1.5, 3.2)):
    x1 , y1 = firstCorner
    x2 , y2 = secondCorner
    test1 , test2 = point
    if (test1 >= x1 and test1 <= x2 and test2 >= y1 and test2 <= y2):
        print('True')
    elif  (test1 >= x1 and test1 <= x2 and test2 <= y1 and test2 >= y2):
        print('True')
    elif (test1 <= x1 and test1 >= x2 and test2 >= y1 and test2 <= y2):
        print('True')
    elif (test1 <= x1 and test1 >= x2 and test2 <= y1 and test2 >= y2):
        print('True')
    else:
        print('False')
P.s. the code is for solving the following problem:
Write a function isIn() which returns boolean True if a point is within a rectangle specified by two sets of coordinates and boolean False if the point is outside the rectangle. The function should accept three parameters:

the first parameter is a set of coordinates which defines one of the corners of the rectangle,
the second parameter is also a set of coordinates that defines the second corner,
the third set of coordinates defines a single point which is being tested.
Gribouillis write Jun-02-2022, 03:37 PM:
Please post all code, output and errors (in it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
Need help solving a problem - by rufenghk - Jun-02-2022, 03:02 PM
RE: Need help solving a problem - by ndc85430 - Jun-02-2022, 03:35 PM
RE: Need help solving a problem - by bowlofred - Jun-02-2022, 03:37 PM
RE: Need help solving a problem - by deanhystad - Jun-02-2022, 07:55 PM
RE: Need help solving a problem - by rufenghk - Jun-02-2022, 09:26 PM
RE: Need help solving a problem - by rufenghk - Jun-02-2022, 08:58 PM
RE: Need help solving a problem - by deanhystad - Jun-03-2022, 12:31 AM
RE: Need help solving a problem - by rufenghk - Jun-04-2022, 10:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  SOlving LInear Equations in Python(Symoy, NUmpy) - Coefficient Problem quest 3 1,765 Jan-30-2022, 10:53 PM
Last Post: quest
  Problem in solving optimization problem Ruchika 0 1,586 Jul-27-2020, 05:28 AM
Last Post: Ruchika

Forum Jump:

User Panel Messages

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