I am making a python program that allows me to calculate the area of a polygon from its coordinates in the plane and for this I have three modules: input.py (to enter the number of sides of the polygon and the coordinates of the vertices), calculations.py (to get the area of the polygon), and output.py (to display the coordinate pairs and the area of the polygon with a message).
In the calculations.py module I have the following:
#cálculos.py
from salida import vértices
def área_polígono():
n=len(vértices)
área=0.0
for i in range(n):
j=(i+1)%n
área+=vértices[i][0]*vértices[j][1]
área-=vértices[j][0]*vértices[i][1]
global área_polígono
área_polígono=0.5*abs(área)
return (área_polígono)
In the output.py module I have the following:
#salida.py
from entrada import x,y
def pares():
""" Esta función permite mostrar los pares ordenados de coordenadas (xi,yi) de cada uno de los vértices del polígono. """
global vértices
vértices=list(zip(x,y))
return(f"Pares= {vértices}")
print(pares())
from cálculos import área_polígono
def área_del_polígono():
""" Esta función permite mostrar el valor del área del polígono. """
return (f"El área del polígono es: {área_polígono} U^2" )
print(área_del_polígono())
When I run the program I get the following:
El área del polígono es: <function área_polígono at 0x7fcf4f7a69d0> U^2
What should I do to get the value of the area of the polygon?
From what I see in the code you are not executing the polygon_area function itself. To execute a function require the parentheses () For example
Response :
Mi valor es : <function funcion at 0x000002CC5960C268>
Now calling the function to be executed with ()
As you can see now if I am calling execute function by using parentheses I hope my answer will help you :)