现有两个元组,元组A ( (5, 7) , (18, 20) , (35, 37), (56, 58) ),元组B (6, 15, 47, 57, 86) 要求你用Python代码统计元组B中的数字落入A中区间的个数(
答:
A= ( (5, 7) , (18, 20) , (35, 37), (56, 58) )
B=(6, 15, 47, 57, 86)
geshu=0
for b in B:
for a in A:
if b in range(a[0],a[1]+1):
geshu+=1
print(geshu)