from numpy import*
id=["A120","A22","A30","D4","A501","R6"]
p=["36.82;10.18","36.86;10.25","36.80;10.15","36.80;10.21","36.95;10.30","36.85;10.20"]
d=array([float]*20)
def trier(d,id,p,pe,n):
    l1=float(pe[0:5])
    l2=float(pe[6:])
    for i in range (n): 
        ch=p[i]
        la=float(ch[0:5])
        lo=float(ch[6:])
        d[i]=sqrt((la-l1)**2+(lo-l2)**2)
        print(d[i])
    ech=True
    while(ech==True):
        ech=False
        for i in range(n-1): 
            if(d[i]>d[i+1]):
                c=d[i+1]
                d[i]=d[i+1]
                d[i+1]=c
                ech=True
                c=id[i]
                id[i]=id[i+1]
                id[i+1]=c
trier(d,id,p,"36.87;10.20",6)
print('les 5 unites les plus proches sont')
a=0
for i in range(5):
    print(id[i])
    ch=id[i]
    if(ch[0]=='A'):
        a=a+1
if(a>=3):
    print("decision : lance l attaque")
else:
    print("ne pas lancer l attaque ")

                         
       

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: