python:使用坐标法计算哨兵控制区

python:使用坐标法计算哨兵控制区,python,Python,这里的新手。我正在尝试创建一个代码,可以计算哨兵控制的简单多边形的面积:用户输入角的坐标,然后在用户输入停止后计算面积,因为他/她至少给出了3个坐标;否则,将出现一条错误消息,提示他输入另一对x坐标和y坐标,直到他给出至少3对 当我尝试运行该程序时,总是会收到以下错误消息: 程序中有一个错误:无效语法 然后变量v以红色突出显示 顺便说一句,这是我的代码: ans = "" sigma2 = 0.0 corner_counter = 1 u1 = float(input("\nx-coordi

这里的新手。我正在尝试创建一个代码,可以计算哨兵控制的简单多边形的面积:用户输入角的坐标,然后在用户输入停止后计算面积,因为他/她至少给出了3个坐标;否则,将出现一条错误消息,提示他输入另一对x坐标和y坐标,直到他给出至少3对

当我尝试运行该程序时,总是会收到以下错误消息: 程序中有一个错误:无效语法

然后变量v以红色突出显示

顺便说一句,这是我的代码:

ans = "" 
sigma2 = 0.0
corner_counter = 1

u1 = float(input("\nx-coordinate of the first corner: "))
v1 = float(input("y-coordinate of the first corner: "))

pu = u1
pv = v1

print "Number of points given: ",corner_counter # just to check the number corners given

while ans != "STOP":

        ans = raw_input("Enter x-coordinate of the next corner or type 'STOP' to compute the area: ")

        if ans == "STOP":
                if corner_counter >= 3:
                    break

                else:
                    u = float(input("ERROR: Must enter at least three (3) corners to compute the area./nEnter x-coordinate of the next corner: ")
                    v = float(input("Enter y-coordinate: "))
                    sigma2 += ((pu * v) - (pv * u))
                    print "(%d * %d) - (%d * %d) =" %(pu, v, pv, u), (pu * v) - (pv * u)
                    print "Partial sum:", sigma2 # to check if the running sum agrees with the expected result
                    corner_counter += 1
                    continue
        else:
           u = float(ans)
           v = float(input("Enter y-coordinate: "))

                sigma2 += ((pu * v) - (pv * u))

                print "(%d * %d) - (%d * %d) =" %(pu, v, pv, u), (pu * v) - (pv * u)
                print "Partial sum:", sigma2 # to check if the running sum agrees with the expected result
                corner_counter += 1
                print "Number of points given: ", corner_counter # for checking purposes

        pu = u
        pv = v

print "(%d * %d) - (%d * %d) =" %(pu, v1, pv, u1), (pu * v1) - (pv * u1)
sigma2 += (u * v1) - (v * u1)
print "\nTOTAL SUM:", sigma2

# final output
print "\nThe area of the", corner_counter,"-sided polygon is", (abs(sigma2)/2), "square unit(s)."  
我已经试着去改变它,但似乎没有任何效果


希望你们能帮助我。非常感谢

您的缩进是混乱的,无论是在原始代码中还是在这里。检查代码是否正确缩进,然后复制/粘贴在这里,如果这不能解决问题。当你正在修复缩进时,考虑使用4个空格。