# Question finding matching numbers in a list

I am new to python and was messing with lists and loops. I want to make a dice game and roll the dice 5 times, store it in a list then find numbers that match in said list. but the out put ends up just giving me the value of the the list length.

import random

dice =

# Roll 5 random numbers

for x in range(0, 5):
x = random.randint(1,6)
dice.append(x)

# find how many time a number in the list was rolled

count = 0
for x in range(6):
count = dice.count(x)
print(“Player rolled:”, dice)
print(count)

The output ends up this:
Player rolled: [3, 3, 3, 1, 3]
[5]
output value should be 4
output next run
Player rolled: [2, 6, 5, 6, 6]
[5]
output value should be 3
How do I find and store the matches in the list and store them in count? Sorry I’m really trying to understand lists and loops but I just can’t figure this out.

1 Like

the following snippet does, what you want:

``````from random import *

dice = []
for x in range(1,6):
dice.append( randint(1,6) )

print(dice)

for x in range(1,6):
print( dice.count(x) )
``````

Note that range(6) starts with index 0.