Page 530 - Computer Science V2.0 Class 11
P. 530

num = int(input(f"Enter number {i + 1}: "))
                        numbers.append(num)



                   mostFrequent = findMostFrequent(numbers)
                   if len(mostFrequent) == 1:
                        print(f"The number that appears the most is: {mostFrequent[0]}")
                   else:

                        print("The following numbers appear the most:")
                        for num in mostFrequent:
                            print(num)
               Program 40: Write a function that takes a list of numbers as input and returns the average of all numbers in the list.


              Ans. def calculateAverage(numberList):
                       '''
                       Objective : To calculate average of numbers in a list
                       Input Parameter : numberList - list

                       Return Value : average – numeric value
                       '''
                       if len(numberList) == 0:

                           return None
                       else:
                           total = sum(numberList)
                           average = total / len(numberList)
                           return average



                   numList = []
                   numElements = int(input("Enter size of the list: "))

                   print("Enter each element and press enter: ")
                   for i in range(0, numElements):   #list input element-wise
                       num = int(input())
                       numList.append(num)
                   print("Contents of list:", numList)



                   averageResult = calculateAverage(numList)
                   if averageResult is not None:
                       print(f"The average of the numbers is: {averageResult}")

                   else:
                       print("The list is empty.")






               516   Touchpad Computer Science (Ver. 2.0)-XI
   525   526   527   528   529   530   531   532   533   534   535