- Write a Python program which accepts the radius of a circle from the user and compute the area. Go to the editor Sample Output : r = 1.1 Area = 3.8013271108436504
My code:
def rad_to_area(rad):
from math import pi
area = pi * (rad**2)
return area
radius = input('Enter radius of circle: ')
print('The area of the circle is', rad_to_area(radius))
Error:
Traceback (most recent call last):
File "/tmp/sessions/167965d8c6c342dd/main.py", line 6, in <module>
print('The area of the circle is', rad_to_area(radius))
File "/tmp/sessions/167965d8c6c342dd/main.py", line 3, in rad_to_area
area = pi * (rad**2)
TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
Could someone please explain what I am doing wrong?
Thanks