如果该点在零件边界内,则算法应返回零件编号。否则,算法应该返回 0。
Part n ({Xmin,Ymin},{Xmax,Ymax}).
Xmin (mm) Ymin (mm) Xmax (mm) Ymax (mm)
Part 1 30 700 180 850
Part 2 650 750 750 870
Part 3 50 20 250 120
Part 4 500 500 700 550
# Function that compares the inputs to the database variables.
def FindPart(xmin, ymin, xmax, ymax, x, y, d) :
for k,v in d.items():
if (x >= xmin and x <= xmax and y >= ymin and y <= ymax) :
v = d.values()
# print(v)
return True
else :
return False
# This is the database of parts
party = {"Part1": [30, 700, 180, 850],
"Part2": [650, 750, 750, 870],
"Part3": [50, 20, 250, 120],
"Part4": [500, 500, 700, 550]}
# Input of parts search
x = int(input('Enter a number: '))
y = int(input('Enter a number: '))
d = party
key_list = list(party.keys())
val_list = list(party.values())
# Loop through the parts bin database and compare inputs
# to find the exact bin
for xmin , ymin , xmax , ymax in party.values():
# Function call
if FindPart(xmin, ymin, xmax, ymax, x, y, d):
w = [i for i, e in enumerate(w) if FindPart(xmin, ymin, xmax, ymax, x, y, d)]
print(w)
break
else:
print("0")`