Page 316 - Computer Science Class 11 Without Functions
P. 316

'''
              Objective: To count number of elements in a list
              Input: a list
              Output: count of elements
              '''


              count = 0
              for element in ageList :
                  count += 1
              print("Count of friends: ", count)






              '''
              Objective: To compute the most frequently occuring element (mode) in a list
              Input: a list of numbers
              Output: mode of the elements of list
              '''
              frequency = {}
              maxCount = 0
              mostFrequent = None
              for element in ageList:
                  if element in frequency:
                      frequency[element] += 1
                  else:
                      frequency[element] = 1

                  if frequency[element] > maxCount:
                      maxCount = frequency[element]
                      mostFrequent = element


              print("The age value that occurs the most is: ",mostFrequent)


                                                  Assessment


        A.  Multiple Choice Questions
           1.  Consider the following statements:
                data1 = (3, 10, 5, 'good', 12.3)
                data2 = [3, 10, 5, 'good', 12.3]
              Which of the following statements is correct?
              a.  Both data1 and data1 are immutable
              b.  data1 is mutable and data2 is immutable
              c.  Both data1 and data2 are mutable
              d.  data1 is immutable and data2 is mutable


         314   Touchpad Computer Science-XI
   311   312   313   314   315   316   317   318   319   320   321