OysterMaker
OysterMaker

Reputation: 329

Float object is not callable python

I have a simple script trying to calculate the area and circumference of a circle. On the first iteration of the loop, it works just fine. However, on the second it breaks saying "'float' object is not callable". Any ideas on what is wrong?

Error Message:

Traceback (most recent call last):
  File "C:/Users/Administrator/Google Drive/School/Spring 2015/Scripting/ITD2313-Portfolio-GandyBrandon/Assignments/Hands-on & Labs/Question1.py", line 16, in <module>
    area = area(radius)
TypeError: 'float' object is not callable

Code:

import math
finished = False
def area(number):
    area = math.pi * (number**2)
    return area
def circum(number):
    c = 2 * math.pi * number
    return c
while (finished == False):
    radius = 0
    radius = int(input("Please input the radius: "))
    if radius <= 0:
        print ("Exitting the program...")
        finished = True
    else:   
        area = area(radius)
        circum = circum(radius)
        print (area)    
        print (circum)

Upvotes: 0

Views: 2867

Answers (1)

anon
anon

Reputation:

You are overriding the function definition:

You're setting

area = area(radius)
circum = circum(radius)

and in the second loop you're going to do the same and so on. Change the name of the function to something like calculate_area or calculateArea and similarly for circum (i.e. calculate_circum or calculateCircum) to avoid such confusions.

Upvotes: 3

Related Questions