Joy
Joy

Reputation: 7

Python functions printing "None"

I want to make fucntions that will find the area of a circle, a washer, and the sum of the squares of a and b. When I run this I get an error saying that TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType' Also I am trying to use my areaCirc function in my areaWasher function.

This is my code.

import math

def areaCirc (r):
    (math.pi * (r ** 2))

print areaCirc(1) # should result in 3.14159265359
print areaCirc(3) # should result in 28.2743338823

def areaWasher (radIn, radOut):
    areaCirc(radOut) - areaCirc(radIn)

print areaWasher(0, 2)  # should result in 12.5663706144
print areaWasher(3, 5)  # should result in 50.2654824574

This is what results from that

None
None
None

Traceback (most recent call last):
  ..., line 18, in <module>
    print areaWasher(0, 2)  # should result in 12.5663706144
  ..., line 16, in areaWasher
    areaCirc(radOut) - areaCirc(radIn)
TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType'

How to I call areaCirc in areaWasher and why is it printing none?

Upvotes: 0

Views: 123

Answers (1)

Art Yerkes
Art Yerkes

Reputation: 1284

Python is an imperative language. To return a value from a function, use the return keyword:

...

def areaCirc (r):
    return (math.pi * (r ** 2))

...

If you don't explicitly return from a function, the return value is None.

Upvotes: 1

Related Questions