Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Got another one
#7
(Feb-17-2020, 06:35 AM)ndc85430 Wrote: You don't even need the if and else. Think about it:

x3 >= x1 and x3 <= x2 and y3 >= y1 and y3 <= y2
is an expression that evaluates to True or False. Based on which, you're setting the value of point_is_in_rectangle - if it's True, you set the variable to True and similarly if it evaluates to False.

So, one can just write

point_is_in_rectangle = x3 >= x1 and x3 <= x2 and y3 >= y1 and y3 <= y2

Yeah, man, that's what I ended up doing. I can't tell you how thankful I am for the help and the explanations. I think I finally figured it out yesterday (I was so busy messing around with it I forgot to keep checking this board). Also, the line about the Boolean statements isn't entirely accurate, I suppose, but still. Here's the final result:

x1 = int(input('Enter the first horizontal value: '))
y1 = int(input('Enter the first vertical value: '))
x2 = int(input('Enter the second horizontal value: '))
y2 = int(input('Enter the second vertial value '))
x = int(input('Please enter an integer '))
y = int(input('Please enter another integer ')) #At this point we've entered all of our points, including the ones we want to tes
if x >= x1 and x <= x2 and y >= y1 and y <= y2: # Using Boolean statements to ensure that our point is within the rectangle.
    print(True)
else:
    print(False)

while True:
    line=input('Do you want to continue (Y/N)? ')
    if line =='Yes':
        continue
    if line =='No':
        break #Asks us to continue or stop, depending on the answer we use.
Reply


Messages In This Thread
Got another one - by DansterTx - Feb-17-2020, 12:53 AM
RE: Got another one - by michael1789 - Feb-17-2020, 01:17 AM
RE: Got another one - by DansterTx - Feb-17-2020, 03:04 AM
RE: Got another one - by jefsummers - Feb-17-2020, 01:21 AM
RE: Got another one - by michael1789 - Feb-17-2020, 03:21 AM
RE: Got another one - by ndc85430 - Feb-17-2020, 06:35 AM
RE: Got another one - by DansterTx - Feb-17-2020, 06:10 PM
RE: Got another one - by jefsummers - Feb-17-2020, 06:45 PM

Forum Jump:

User Panel Messages

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