簡體   English   中英

我在python中使用此代碼時出現“無效語法”錯誤。 幫我找一個補救措施?

[英]I've got an “invalid syntax” error with this code in python. Help me find a remedy?

def(pentagon): chunk中我將變量命名為“ 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() 

這一行:

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

缺少一個關閉的人。 編程需要關注許多細節......

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

你錯過了一個結束)

事實上我注意到你在rhombuspentagontrapezoid中的其他input語句有類似的問題,你可能復制了代碼:)

您可能希望使用能夠幫助您匹配開括號和右括號的編輯器。 它有助於避免這些錯誤。

缺少右括號: s = int(input('What is the side length'))

這些行中缺少結束括號:

在函數五邊形()

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

在函數菱形()

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')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM