Calcule l’image d’un intervalle par la fonction carré.
usage : carre(“]-1,2]”) affiche “[0,4]”
def carre(interval): c0,c1=interval[0],interval[-1] a,b=map(int,interval[1:-1].split(",")) inv={"]":"[","[":"]"} ch="%s%d,%d%s" if a*b>0: if a>0: print(ch%(c0,a*a,b*b,c1)) else: print(ch%(inv[c1],b*b,a*a,inv[c0])) elif a*b==0: if a*a>0: print(ch%(inv[c1],0,a*a,inv[c0])) else: print(ch%(c0,0,b*b,c1)) else: if a*a==b*b: if c0=="]" and c1=="[": print(ch%("[",0,a*a,"[")) else: print(ch%("[",0,a*a,"]")) elif a*a<b*b: print(ch%("[",0,b*b,c1)) else: print(ch%("[",0,a*a,inv[c0]))