python⽆效语法怎么解决_我在python中使⽤此代码时出现“⽆
效语法”错误。帮我⼀。。。
在def(pentagon):块中,我命名了⼀个变量“first”。但是,这会导致“⽆效的语法”错误。怎么了?我试过把它命名为其他东西,从单个字母到像“preArea”这样的较低/⼤写字母的组合。
def display():
print('This program will tell you the area some shapes')
print('You can ')
print('1. rectangle 2. triangle')
print('3. circle 4. pentagon')
print('5. rhombus 6. trapezoid')python新手代码错了应该怎么改
def shape():
shape = int(input('What shape do you choose?'))
if shape == 1: rectangle()
elif shape == 2: triangle()
elif shape == 3: circle()
elif shape == 4: pentagon()
elif shape == 5: rhombus()
elif shape == 6: trapezoid()
else:
print('ERROR: select 1 2 3 4 5 or 6')
shape()
def rectangle():
l = int(input('What is the length?'))
w = int(input('What is the width?'))
areaR=l*w
print('The ')
print(areaR)
def triangle():
b = int(input('What is the base?'))
h = int(input('What is the height?'))
first=b*h
areaT=.5*first
print('The ')
print(areaT)
def circle():
r = int(input('What is the radius?'))
preCircle = r**2
areaC = 3.14*preCircle
print('The ')
print(areaC)
def pentagon():
s = int(input('What is the side length')
first = s**2
areaP = 1.72*first
print('The ')
print(areaP)
def rhombus():
b = int(input('What is the base?')
h = int(input('What is the height?')
areaR = b*h
print('The ')
print(areaR)
def trapezoid():
baseOne = int(input('What is the first base?') baseTwo = int(input('What is the second base?') h = int(input('What is the height')
first = baseOne*baseTwo
second = first/2
areaT = second*h
print('The ')
print(areaT)
if __name__=="__main__":
display()
shape()
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论