I want to make a python script which checks this, but the point i will be using are (for example) x = 1290 to 1340 and y = 1460 to 1510 (this means that A = 1290 B = 1340 C = 1460 and D = 1510), i have already made a simple script but it needs me to write every single possible coordinate mannualy… here it is:
JavaScript
x
17
17
1
print ("")
2
print ("1923 1682")
3
print ("")
4
print ("Click below here to type!")
5
6
NFGCOORDINATES = (//here every single possible coordinate will come)
7
guess = str(input())
8
9
if guess in NFGCOORDINATES:
10
print ("Coordinates are in NFG area")
11
print ("")
12
print ("Made by El_Capitano with love!")
13
else:
14
print ("Coordinates are NOT in NFG area")
15
print ("")
16
print ("Made by El_Capitano with love!")
17
Anyone has tips to make this either easier or make a total different script?
Advertisement
Answer
Assuming that the sides of the square are parallel to the coordinate axis, you just have to check if the x
input is between the limits and that the y
input is between the limits. Also, assuming the limits are inclusive (i.e. x == 1290
is inside the square). Thus:
JavaScript
1
19
19
1
print('Your input should be of the form: 1923 1682')
2
guess = input()
3
try:
4
x, y = [int(val) for val in guess.split()]
5
except: # This is a very crude check.
6
print('Wrong input format')
7
raise
8
9
# Limits of the rectangle
10
x_low = 1290
11
x_high = 1340
12
y_low = 1460
13
y_high = 1510
14
15
if (x_low <= x <= x_high) and (y_low <= y <= y_high):
16
print ("Coordinates are in NFG area")
17
else:
18
print ("Coordinates are NOT in NFG area")
19