Good morning everyone here: to begin with, I'm quite new to python. I am currently taking a course in which they ask me:
Write a function def estaEn(esquinauno=(0,0), esquinados=(0,0), prueba=[]):
that returns True/False
whether a number of points is inside or outside a specified coordinate (a1, b1), (a2, b2)
. The function must accept three parameters:
1.The first parameter is a set of coordinates that defines one of the "corners" of a figure (a1, b1)
,
the second parameter is also a set of coordinates defining the second "corner"
(a2, b2)
,the third set of coordinates defines the area being tested, that is, the test value.
I get these test points:
estaEn((0,0), (5,5), [(1,1), (0,0), (5,5)]) #debería ser True
estaEn((0,0), (5,5), [(1,1), (0,0), (5,6)]) #debería ser False
estaEn((0,0), (5,5), []) #debería ser False --> lista vacía.
I have tried running something like this:
#Función base dada
def estaEn(esquinauno=(0,0), esquinados=(0,0), puntos=[]):
#definición del índex de mis puntos:
a1,b1=esquinauno[0],esquinauno[1]
a2,b2=esquinados[0],esquinados[1]
#como son 3 puntos a probar intento indexar 3 pares de puntos
a,b,c=puntos[0][0], puntos[0][0], puntos[0][0]
#Intento hacer un if para verificar si el valor es nulo o vacío.
if len(puntos) == 0:
return False
elif(a >= a1 and a <= a2):
return True
elif(a >= a2 and a <= a1):
return True
elif(b >= b1 and b <= b2):
return True
elif(b >= b2 and b <= b1):
return True
elif(c >= c2 and c <= c1):
return True
elif(c >= c2 and c <= c1):
return True
else:
return False
But when I try I get
estaEn((0,0), (5,5), [(1,1), (0,0), (5,5)]) ---> True
estaEn((0,0), (5,5), [(1,1), (0,0), (5,6)]) ---> True
estaEn((0,0), (5,5), [])
----> a,b,c=pointList[0][0], pointList[0][0], pointList[0][0]
IndexError: list index out of range
Someone who understands the subject better give me a hand. I don't know if maybe there is a more intuitive and easier way to do the same thing and I'm not looking at it.
I will be very grateful to anyone who wants to help me. Greetings to all.