(Python) How to find the number of occurrences in a list?
<p>Instead of using the .count function, I'm trying to determine the number of times a number input by a user occurs in a list. Appended to the originally empty list are 20 random integers between 1 and 10.</p>

<pre><code>import random

print()
num_list = []

for num in range(20):
    num_list.append(random.randint(1, 10))

chosen_num = eval(input("Enter a number between 1 and 10, inclusive: "))

occurences = num_list.count(chosen_num)

print()
print("The number " + str(chosen_num) + " occurs " + str(occurences) + " time(s) in the list ")
</code></pre>

<p>Is there any way I can use a "for" loop or if-else statement to determine the number of times a number appears in the list, rather than using .count?</p>

<p>Thanks.</p>

<p>Yes. </p>

<pre><code>counter = 0
for n in list_of_stuff:
    if n == what_to_count_occurences_of:
        counter += 1
</code></pre>

<p>For non homework uses, use count. </p>

python