Python Question Define a function calculateareas arr that t
Python Question
Define a function calculate_areas( arr ) that takes in an array of radii and returns an array containing the areas of circles with the given radii.
 
 Example Usage:
 >>> print calculate_areas(np.array([1, 2, 3, 4, 5]))
 [ 3.14159265 12.56637061 28.27433388 50.26548246 78.53981634]
Solution
import numpy as np
 import math
 def calculate_areas(arr):
area_list=[]#list store areas of given radii
   for r in arr:
        area=math.pi*r*r #formula area=3.14*r*r
        area_list.append(area)#put in area list
return area_list#return area list
 print calculate_areas(np.array([1, 2, 3, 4, 5]))#print area list
===========================================================
Output:
akshay@akshay-Inspiron-3537:~/Chegg$ python area.py
 [3.141592653589793, 12.566370614359172, 28.274333882308138, 50.26548245743669, 78.53981633974483]

