sum=0.0
b=input("Number of corners: ")
while b < 2:
print "Invalid number of corners."
for i in range (b):
xcoor=(i+1)
X=input ("x-coordinate:")
ycoor=(i+1)
Y=input ("y-coordinate:")
if i==0:
x1=X
y1=Y
xp=X
yp=Y
elif i>=0:
sum+=(xp*Y-yp*X)
xp=X
yp=Y
sum=sum+(X*y1-Y*x1)
area=(sum/2.0)
a=abs(area)
print "Area= %.1f" % (a)
the answer is always wrong. why? Thank you. I'm a newbie..I cant seem to find the area and sometimes it gives Area=0.0
When I try to run the code and enter coordinates as x and y, this happens:
Number of corners: 4
x-coordinate:2
y-coordinate:3
x-coordinate:4
y-coordinate:2
x-coordinate:5
y-coordinate:6
x-coordinate:7
y-coordinate:2
Area= 4.5.
If I were to calculate the area manually, the result should be 18.