得到结果“无”

时间:2019-09-25 18:31:10

标签: python

在编写程序时,输入形状的名称和尺寸后,将输出形状的面积和周长。它一直工作到我的五边形代码,但是在该区域之后,它只返回一个作为区域:

import math

def perimeter_pentagon(lenght): #function for perimiter of pentagon 
    pentPerimeter=5*length
    return(pentPerimeter)

def area_pentagon(length): #function for area of a pentagon
    PentagonArea=(1/4*math.sqrt(5*(5+2*math.sqrt(5)))*length*length)

shape=input("Enter your shape ") #asks the user for their shape
(skipping the other if and elif statments)
else:
    length=float(input("Enter the length "))
    PentagonArea=area_pentagon(length)
    PentagonPerimeter=perimeter_pentagon(length)
    print("The area of your pentagon is: ", PentagonArea)
    print("The perimeter of your pentagon is: ", PentagonPerimeter)

1 个答案:

答案 0 :(得分:1)

您需要从函数中返回值。

def area_pentagon(length): #function for area of a pentagon
    PentagonArea=(1/4*math.sqrt(5*(5+2*math.sqrt(5)))*length*length)
    return PentagonArea

或仅将其缩短到return语句:

def area_pentagon(length): #function for area of a pentagon
    return (1/4*math.sqrt(5*(5+2*math.sqrt(5)))*length*length)