0
Need help with my sample code - functions
print area of circle using custom function: import math r = input("Enter the radius: ") def circleArea(): return math.pi*pow(r,2) print("Area is ", circleArea()) I am getting an error message
4 Answers
+ 4
import math
r = float(input("Enter the radius: "))
def circleArea():
return math.pi*pow(r,2)
print("Area is ", circleArea())
+ 3
The r you get from input has type string, while the pow function requires an input of a numeric data type. This should work:
import math
def circleArea(radius):
return math.pi*radius*radius
r = float(input("Enter the radius:\n"))
print("Area is", circleArea(r))
+ 3
Anytime Ved
+ 1
Thanks Meharban and Tobi for the answers. 'float' was missing.