Created
January 13, 2021 22:23
-
-
Save ayubmetah/83f2863cce92093cc56a9172022a727d to your computer and use it in GitHub Desktop.
This code snippet uses one function. The count_occurance function counts how many times a number appears in the “values” list. This function iterates over all the values in “values” and keeps a running total of all those equal to a particular number. This number is specified as a parameter called “to_find”.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def count_occurrence(values, to_find): | |
number_of_occurrences = 0 | |
for v in range(len(values)): | |
if values[v] == to_find: | |
number_of_occurrences += 1 | |
return number_of_occurrences | |
values = [1, 2, 3, 3] | |
check_for_threes = count_occurrence(values, 3) | |
print(check_for_threes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment