In: Computer Science
Function named FunCount takes three arguments-
C, an integer representing the count of elements in input list
IP- input list of positive integers.
Item- an integer value.
Function FunCount returns an integer representing the
count of all the elements of List that are equal to
the given integer value Key.
Example: Don’t take these values in program, take all inputs from user
C = 9, IP= [1,1,4,2,2,3,4,1,2], Item = 2
function will return 3
CODE:-
def FunCount(C,IP,Item): # this is the required function count = 0 # initialising the count with 0 for i in range(C): # then iterating in the range of C if IP[i] == Item: # then checking if the element is equal to item count+=1 # if yes increasing the value of count return count # then at last retuning it if __name__ == '__main__': # this is the main method C = int(input("Enter the value of C: ")) # taking the input from the user IP = list(map(int,input("Enter element: ").split())) # then taking the list from the user Item = int(input("Enter the value of Item: ")) # then item print(FunCount(C,IP,Item)) # finally printing the method return
OUTPUT:-
FOR ANY OTHER QUERY PLEASE COMMENT.