在正确的语法行上获取无效语法
Getting Invalid syntax on a correct line of syntax
我在 运行 这段代码时收到一个无效的语法错误,但是当我检查错误行时,它似乎是正确的。这是一个用于计算抛物线部分的代码。
def PCalculator():
print("What are you missing?")
print("D for directrix")
print("F for focus")
print("V for vertex")
inp = input("Answer D, V, or F: ").lower()
if inp == "v":
fx = input("What is the X value of the focus? ")
fy = input("What is the Y value of the focus? ")
d = input("What is the Y value of the directrix? ")
ptlst = [fx, fy, d]
stopper = 1
for x in ptlst:
if (x.strip("-")).isnumeric() == False:
stopper = 0
if stopper == 1:
fx = int(fx)
fy = int(fy)
d = int(d)
vy = fy - ((abs(fy - d)/2)
print("The vertex is (" + str(fx) + ", " + str(vy) + ")") #this is where I am having the error
elif inp == "f":
vx = input("What is the X value of the vertex? ")
vy = input("What is the Y value of the vertex? ")
d = input("What is the Y value of the directrix? ")
ptlst = [vx, vy, d]
stopper = 1
for x in ptlst:
if (x.strip("-")).isnumeric() == False:
stopper = 0
if stopper == 1:
vx = int(vx)
vy = int(vy)
d = int(d)
fy = vy + (abs(vy - d))
print("The focus is (" + str(vx) + "," + str(fy) + ")")
else:
print("ERROR: Letter detected")
PCalculator()
你在这行有一个额外的左括号:
vy = fy - ((abs(fy - d)/2)
我在 运行 这段代码时收到一个无效的语法错误,但是当我检查错误行时,它似乎是正确的。这是一个用于计算抛物线部分的代码。
def PCalculator():
print("What are you missing?")
print("D for directrix")
print("F for focus")
print("V for vertex")
inp = input("Answer D, V, or F: ").lower()
if inp == "v":
fx = input("What is the X value of the focus? ")
fy = input("What is the Y value of the focus? ")
d = input("What is the Y value of the directrix? ")
ptlst = [fx, fy, d]
stopper = 1
for x in ptlst:
if (x.strip("-")).isnumeric() == False:
stopper = 0
if stopper == 1:
fx = int(fx)
fy = int(fy)
d = int(d)
vy = fy - ((abs(fy - d)/2)
print("The vertex is (" + str(fx) + ", " + str(vy) + ")") #this is where I am having the error
elif inp == "f":
vx = input("What is the X value of the vertex? ")
vy = input("What is the Y value of the vertex? ")
d = input("What is the Y value of the directrix? ")
ptlst = [vx, vy, d]
stopper = 1
for x in ptlst:
if (x.strip("-")).isnumeric() == False:
stopper = 0
if stopper == 1:
vx = int(vx)
vy = int(vy)
d = int(d)
fy = vy + (abs(vy - d))
print("The focus is (" + str(vx) + "," + str(fy) + ")")
else:
print("ERROR: Letter detected")
PCalculator()
你在这行有一个额外的左括号:
vy = fy - ((abs(fy - d)/2)