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 に答える