0

我想调用任一方法(getPerimeter | getArea)并根据提供的输入返回答案。

#!usr/bin/python

def getPerimeter(x, y):
    answer = (2 * x) + (2 * y)
    return string(answer)  **This will not return anything in my terminal**
def getArea(x, y):  
    answer = x * y 
    return string(answer)   **This also will not return anything in my terminal**

reply = raw_input("Do you want to find the area or the perimeter? ")

if reply == "area":
    response1 = raw_input("What is the length ?: ")
    response2 = raw_input("What is the width ?: ")
    response1Int = int(response1)
    response2Int = int(response2)
    getArea(response1Int, response2Int)
else:
    response3 = raw_input("What is the length ?: ")
    response4 = raw_input("What is the width ?: ")
    response3Int = int(response3)
    response4Int = int(response4)
    getPerimeter(response3Int, response4Int)
4

2 回答 2

3

return返回,它没有print

于 2012-09-12T20:19:55.127 回答
2

从函数返回某些内容不会将其打印到屏幕上。尝试print(getArea(response1Int, response2Int))print(getPerimeter(response1Int, response2Int))

另外,string不是函数。

于 2012-09-12T20:20:24.003 回答