Need help with my sample code - functions | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

28th Mar 2017, 1:46 PM
Ved
Ved - avatar
4 Answers
+ 4
import math r = float(input("Enter the radius: ")) def circleArea(): return math.pi*pow(r,2) print("Area is ", circleArea())
28th Mar 2017, 2:00 PM
Meharban Singh
Meharban Singh - avatar
+ 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))
28th Mar 2017, 1:59 PM
Tob
Tob - avatar
+ 3
Anytime Ved
28th Mar 2017, 6:03 PM
Meharban Singh
Meharban Singh - avatar
+ 1
Thanks Meharban and Tobi for the answers. 'float' was missing.
28th Mar 2017, 5:55 PM
Ved
Ved - avatar