0

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)
3
  • 3
    You have variables named area and circum, and functions with the same name. Don't do that. Also, next time, please post the full text of the error or traceback, as it points directly to where the error is occurring. Commented Apr 2, 2015 at 18:57
  • 1
    Not answering your question, but your variable finished is a boolean. You should not explicitly write while finished == False, you can just use the boolean itself, like this: while finished or while ! finished. Commented Apr 2, 2015 at 18:58
  • @JNevens I tried that syntax by Python was not having it. Commented Apr 2, 2015 at 19:12

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

No problem. You should generally try to stick to rules when naming objects in general, you'll see that you'll face such problem less frequently and it will save you time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.