python编程中的错误
我对这段代码有问题,它说第17行的语法无效python编程中的错误,python,Python,我对这段代码有问题,它说第17行的语法无效 import math def SA(): side = int(input("What is the side of the square?: ")) print("The Area of The Square is " + str(side**2) + ".") def PA(): hight = int(input("What is The Hight of The Parallelogram?: ")) sid
import math
def SA():
side = int(input("What is the side of the square?: "))
print("The Area of The Square is " + str(side**2) + ".")
def PA():
hight = int(input("What is The Hight of The Parallelogram?: "))
side = int(input("What is The side of The Parallelogram?: "))
print("The Area of The Parallelogram is "+str(hight*side)+".")
def TA():
hight = int(input("What is The Hight of The Triangle?: "))
side = int(input("What is The Side of The Triangle?: "))
print("The Area of Triangle is "+str((hight*side)/2)
def ca():
r = int(input("What is the Radious of The Circle?: "))
print("The Area of the Circle is " str(math.pi*r**2)
def main():
op = input("Enter the operation You Want to do c = circle, s = square, p = parallelogram, t = triangle: ")
if op == "c":
ca()
elif op == "s":
SA()
elif op == "p":
PA()
elif op == "t":
TA()
else:
print("INVALID OPERATION!")
input("Press Enter To Continue...")
main()
如果有人能帮我,我将不胜感激。
谢谢。在代码中查看我的评论:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import math
def SA():
side = int(input("What is the side of the square?: "))
print("The Area of The Square is " + str(side**2) + ".")
def PA():
hight = int(input("What is The Hight of The Parallelogram?: "))
side = int(input("What is The side of The Parallelogram?: "))
print("The Area of The Parallelogram is "+str(hight*side)+".")
def TA():
hight = int(input("What is The Hight of The Triangle?: "))
side = int(input("What is The Side of The Triangle?: "))
# it's lack of a right bracket here
print("The Area of Triangle is "+str((hight*side)/2))
def ca():
r = int(input("What is the Radious of The Circle?: "))
# it's lack of a comma and a right bracket here
print("The Area of the Circle is ", str(math.pi*r**2))
def main():
op = input("Enter the operation You Want to do c = circle, s = square, p = parallelogram, t = triangle: ")
if op == "c":
ca()
elif op == "s":
SA()
elif op == "p":
PA()
elif op == "t":
TA()
else:
print("INVALID OPERATION!")
input("Press Enter To Continue...")
main()
输出:
Enter the operation You Want to do c = circle, s = square, p = parallelogram, t = triangle:
你有很多小的语法错误。您还必须使用
raw\u input
而不是input
。你知道为什么吗?为你锻炼
import math
def SA():
side = int(input("What is the side of the square?: "))
print("The Area of The Square is " + str(side**2) + ".")
def PA():
hight = int(input("What is The Hight of The Parallelogram?: "))
side = int(input("What is The side of The Parallelogram?: "))
print("The Area of The Parallelogram is "+str(hight*side)+".")
def TA():
hight = int(input("What is The Hight of The Triangle?: "))
side = int(input("What is The Side of The Triangle?: "))
print("The Area of Triangle is "+str((hight*side)/2))
def ca():
r = int(input("What is the Radious of The Circle?: "))
print("The Area of the Circle is "+str(math.pi*r**2))
def main():
op = raw_input("Enter the operation You Want to do c = circle, s = square, p = parallelogram, t = triangle: ")
print 'You have entered : ', op
if op == "c":
ca()
elif op == "s":
SA()
elif op == "p":
PA()
elif op == "t":
TA()
else:
print("INVALID OPERATION!")
input("Press Enter To Continue...")
main()
我建议您使用一些IDE,比如vim、emacs、pycharm、sublime或pyscriptor,它们可以帮助您找到这些语法错误/缩进错误 如果你能明确指出第17行是什么,那就太好了。
print(“三角形的面积是”+str((高*边)/2)
和print(“圆的面积是”str(math.pi*r**2)没有打印的结束标记。你应该考虑选择一个更好的开发环境。我的意思是你的编辑应该告诉你语法错误,也要标出正确的位置。如果我的答案有帮助,别忘了接受它。谢谢!非常感谢。我会努力更好地忽略我的工作。@ NikolayMiroshnichenkoNikolax,如果我的ANSWE。r帮助你,别忘了接受它。