ARRAY: An array can be defined as a container object that is used to hold a fixed number of values of a single type of data. The main purpose of an array is to store multiple items of the same type together.
Suppose you are given with an array that contains ints. Your task is to return the number of 3 in the array.
Here we have to again consider a variable which is initially equal to zero to keep the count of a number of 3 and also our function is only defined for nums as our array would only contain integers as mentioned earlier.
Code:
def Count3(nums):
count = 0
for num in nums:
if num == 3:
count = count + 1
return count
print (Count3([1,2,3,4,3,3,3,]))
Here we have to again consider a variable which is initially equal to zero to keep the count of a number of 3 and also our function is only defined for nums as our array would only contain integers as mentioned earlier.
Code:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer