write a method called percenteven that accepts an array of integers as a parameter and returns the percentage of even numbers in the array as a real number. for example, if the array stores the elements {6, 2, 9, 11, 3}, then your method should return 40.0. if the array contains no even elements or no elements at all, return 0.0.

Respuesta :

This program require to write a function that calculate the average of the even numbers in the array. The function perecentEven print the average of the even number while taking array of integer as an argument or parameter.

The above functionality is implemented in Python language as given in the below code and output of the code is also attached.

from array import * # import array related functionality.

def percentEven(a):#here 'i' defines the datatype of the array as integer

   evenNumber=[] # array to capture even number

   oddNumber=[] #array to capture odd number

   average=0 # average variable

   total=0 # total of positive number in array

   count=0 # count the positive number in array

   if len(a)>0: # check if the provided array has an element(s)

       for i in a: # iterate through the array

           if (i%2==0): # check if the number in the array is positive

               evenNumber.append(i)# store that number in array of #evenNumber

               count=count+1 #count the positive number in array

           else: #else the number in array is odd

               oddNumber.append(i) # add that number into array of #oddNumber

       if len(evenNumber)>0: # now check if evenNumber array has some #value

           for i in evenNumber: # iterate through every even number

               total= total+i # add the even number

           average=total/count # calculate average

           print(average) # print average

       else:

           print(0.0) # if array is empaty or have odd values then print 0.0

   

arr = array('i',[6, 2, 9, 11, 3]) # here 'i' defines the datatype of integer, and

#declare an array of integers

percentEven(arr) # pass the array to function.

You can learn more about function in Python at

https://brainly.com/question/25755578

#SPJ4

Ver imagen asarwar