2

def(pentagon):チャンクでは、変数に " " という名前を付けましたfirst。ただし、これにより「無効な構文」エラーが発生します。どうしたの?単一の文字から「preArea」のような小文字/大文字の組み合わせまで、さまざまな名前を付けてみました。

def display():
    print('This program will tell you the area some shapes')
    print('You can choose between...')
    print('1. rectangle    2. triangle')
    print('3. circle       4. pentagon')
    print('5. rhombus      6. trapezoid')

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 area is...')
    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 area is...')
    print(areaT)


def circle():
    r = int(input('What is the radius?'))
    preCircle = r**2
    areaC = 3.14*preCircle
    print('The area is...')
    print(areaC)


def pentagon():
    s = int(input('What is the side length')
    first = s**2
    areaP = 1.72*first
    print('The area is...')
    print(areaP)


def rhombus():
    b = int(input('What is the base?')
    h = int(input('What is the height?')
    areaR = b*h
    print('The area is...')
    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 area is...')
    print(areaT)


if __name__=="__main__":
    display() 
    shape() 
4

4 に答える 4

5

この行:

s = int(input('What is the side length')

閉じ括弧がありません。プログラミングには、多くの詳細に注意を払う必要があります...

于 2012-06-23T01:58:57.903 に答える
3
 s = int(input('What is the side length')

クロージングがありません)

input実際、私はあなたの他のステートメントでrhombus同様の問題pentagonを抱えていることに気付きました.trapezoid おそらくコードをコピーしました:)

開き括弧と閉じ括弧を一致させるのに役立つエディターを使用することをお勧めします。この種のエラーを回避するのに役立ちます。

于 2012-06-23T01:59:39.570 に答える
2

閉じ括弧がありません:s = int(input('What is the side length'))

于 2012-06-23T01:59:36.710 に答える
0

次の行には閉じ括弧がありません。

関数 pentagon() で

s = int(input('What is the side length')

関数 rhombus() で

b = int(input('What is the base?')
h = int(input('What is the height?')

関数内のtrapezoid()

baseOne = int(input('What is the first base?')
baseTwo = int(input('What is the second base?')
h = int(input('What is the height')
于 2012-06-23T02:54:06.300 に答える