samedi 28 novembre 2020

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
        
#I start with an empty list
            
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 I'm looking for is 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

Aucun commentaire:

Enregistrer un commentaire