Complete novice here trying to learn. I am supposed to create a module which I believe I have done here:
import math
def circum(x):
return 2 * math.pi * x (format (",.3f"))
def area(x):
return math.pi * x **2 (format (",.3f"))
I have named this module mycircle. Now I have to import this module and use it to calculate the circumference and area of a circle. My code for this is:
import mycircle
def main():
radius = float (input ("Please enter the radius of the circle: "))
circumference = mycircle.circum (radius)
area = mycircle.area (radius)
print ("The circumference of the circle is ", format (mycircle.circum, ",.3f"), sep="")
print ("The area of the circle is ", format (mycircle.area, ",.3f"), sep="")
main()
However, I am receiving the error:
File "C:/Users/Jameson/Desktop/COP 1000/Chapter 5/54.py", line 26, in <module>
main()
File "C:/Users/Jameson/Desktop/COP 1000/Chapter 5/54.py", line 21, in main
circumference = mycircle.circum (radius)
File "C:/Users/Jameson/Desktop/COP 1000/Chapter 5\mycircle.py", line 4, in circum
return 2 * math.pi * x (format (",.3f"))
TypeError: 'float' object is not callable
I can only assume that it is something dumb. Any help would be greatly appreciated! I am stuck here.
format
in yourmycircle
module. But you probably shouldn't be trying to format the numbers in those functions - just return the numeric values. That way you can use the results in further calculations, if desired. Only format numbers when you're ready to output them.To learn more about how to useformat
, please see the docs for the Format Specification Mini-Language. – PM 2Ring Feb 23 '16 at 3:07