运行程序时出现SyntaxError

时间:2016-12-02 16:57:44

标签: python stdin sys

我必须使用argv.sys制作计算器。当我运行我的代码时,我不断收到此错误:

>>> "C:\Users\admin\Desktop\uni\Informatik BW\assignment.py" + rect 0 0 10 10
    File "<stdin>", line 1
    "C:\Users\admin\Desktop\uni\Informatik BW\assignment.py" + rect 0 0 10 10
                                                                    ^
SyntaxError: invalid syntax
>>>

这是我的计划:

import sys
import math

def area_rectangle(x,y,widht,height):
    return (widht*height)
def xy_centroid_rectangle(x,y):
    return (k + l * 0.5)

#def area_circle(x,y,r):
    #return (r*r*math.pi)
#def xy_centroid_circle(k,r):
#   return ((4 * r / 3 * math.pi) * 2)

#def area_half_circle(x,y,r):
#   return (r * r * math.pi / 2)
#def xy_centroid_half_circle(k,r):
#   return (4 * r / 3 * math.pi)

#def area_right_triangle(x,y,a,h):
#   return (a * h / 2)
#def xy_centroid_right_triangle(k,l):
#   return (a + h + math.sqrt((a * a) + (h * h)))

x = 0
y = 0
a = 0 
fx = 0
fy = 0
f = 0
i = 1

while i < len(sys.argv):

    vz = sys.argv[i]
    print i
    print vz
    if sys.argv[i + 1] == "rect":
        f = area_rectangle(float(sys.argv[i + 2]),float(sys.argv[i + 3]),float(sys.argv[i + 4]),float(sys.argv[i + 5]))
        fx = xy_centroid_rectangle(float(sys.argv[i + 2]),float(sys.argv[i + 4]))
        fy = xy_centroid_rectangle(float(sys.argv[i + 3]),float(sys.argv[i + 5]))
        i += 6

    #if sys.argv[i + 1] == "circ":
        #f = area_circle(float(sys.argv[i + 2]),float(sys.argv[i + 3]),float(sys.argv[i + 4]))
        #fx = xy_centroid_circle(foat(sys.argv[i + 2]),float(sys.argv[i + 4]))
        #fy = xy_centroid_circle(foat(sys.argv[i + 3]),float(sys.argv[i + 4]))
        #i += 5

    #if sys.argv[i + 1] == "halfcirc":
        #f = area_circle(float(sys.argv[i + 2]),float(sys.argv[i + 3]),float(sys.argv[i + 4]))
        #fx = xy_centroid_circle(foat(sys.argv[i + 2]),float(sys.argv[i + 4]))
        #fy = xy_centroid_circle(foat(sys.argv[i + 3]),float(sys.argv[i + 4]))
        #i += 5

    #if sys.argv[i + 1] == "righttri":
        #f = area_rectangle(float(sys.argv[i + 2]),float(sys.argv[i + 3]),float(sys.argv[i + 4]),float(sys.argv[i + 5]))
        #fx = xy_centroid_rectangle(float(sys.argv[i + 2]),float(sys.argv[i + 4]))
        #fy = xy_centroid_rectangle(float(sys.argv[i + 3]),float(sys.argv[i + 5]))
        #i += 6

    if vz == "+":
        x = (x * a + fx * f) / (a + f)
        y = (y * a + fy * f) / (a + f)
        a = a + f 
    if vz == "-":
        x = (x * a - fx * f) / (a - f)
        y = (y * a - fy * f) / (a - f)
        a = a - f


print x
print y
print a

为什么我收到此错误?

0 个答案:

没有答案