user1666862
user1666862

Reputation:

Text will not print in the Python interpreter from these two methods I made

I want to call either method (getPerimeter | getArea) and return the answer depending on the input provided.

#!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)

Upvotes: 0

Views: 96

Answers (2)

Jonathan Paulson
Jonathan Paulson

Reputation: 1058

Returning something from a function doesn't print it to the screen. Try print(getArea(response1Int, response2Int)) and print(getPerimeter(response1Int, response2Int))

Also, string is not a function.

Upvotes: 2

user647772
user647772

Reputation:

return returns, it doesn't print.

Upvotes: 3

Related Questions