Roulette Winning numbers Counter

Roulette Winning Numbers Counter

 

The list “roulette” contains the winning numbers of a casino roulette game in the last hour. Your task is to write a Python 3 function that counts the frequency of each number in the list “roulette”. Your program should count how many times each number has appeared as a winner.

roulette = [‘0’,’3’,’21’,19’,’0’,’16’, ‘18’, ‘19’,’3’, ‘21’, ‘23’,’5’,’6’, ‘25’, ‘27’,’2’,’15’,’19’,’32’, ‘4’, ‘6’, ‘8’,’31’, ‘3’,’10’, ‘11’, ‘13’, ‘15’, ‘17’, ‘20’,’21’,’30’,’28’,’10’,’2’,’13’,’9’,’25’,’7’,’9’,’29’,’34’, ‘3’,’0’,’16’,’11’,’5’,’3’,’12’,’19’,’26’]

The objective of this Python project on lists and dictionaries is to practice dictionaries, iterating through lists, and performing frequency counts in Python.

Guide

To complete this Python project, follow these steps:

1. Define the list “roulette” with the provided winning numbers.
2. Create a dictionary to store the frequency of each number.
3. Iterate over each number in the “roulette” list.
4. Check if the number is already a key in the dictionary.
5. If the number is not a key, add it to the dictionary with a value of 1.
6. If the number is already a key, increment its value by 1.
7. After iterating through all the numbers, the dictionary will contain the frequency of each number.
8. Print the dictionary to display the count of each number.

Expected Output

The number 0 has won 3 times.
The number 3 has won 5 times.
The number 21 has won 3 times.
The number 19 has won 4 times.
The number 16 has won 2 times.
The number 18 has won 1 times.
The number 23 has won 1 times.
The number 5 has won 2 times.
The number 6 has won 2 times.
The number 25 has won 2 times.
The number 27 has won 1 times.
The number 2 has won 2 times.
The number 15 has won 2 times.
The number 32 has won 1 times.
The number 4 has won 1 times.
The number 8 has won 1 times.
The number 31 has won 1 times.
The number 10 has won 2 times.
The number 11 has won 2 times.
The number 13 has won 2 times.
The number 17 has won 1 times.
The number 20 has won 1 times.
The number 30 has won 1 times.
The number 28 has won 1 times.
The number 9 has won 2 times.
The number 7 has won 1 times.
The number 29 has won 1 times.
The number 34 has won 1 times.
The number 12 has won 1 times.
The number 26 has won 1 times.

Visit Practity for more interesting Python projects!

Source Code

## We define the provided list 
roulette = ['0', '3', '21', '19', '0', '16', '18', '19', '3', '21',
 '23', '5', '6', '25', '27', '2', '15', '19', '32', '4', '6', '8',
 '31', '3', '10', '11', '13', '15', '17', '20', '21', '30', '28',
 '10', '2', '13', '9', '25', '7', '9', '29', '34', '3', '0', '16', 
'11', '5', '3', '12', '19', '26']

## Write the function to count the ocurrences
def count_winning_numbers(roulette_list):
    winning_counts = {}
    for number in roulette_list:
        if number in winning_counts:
            winning_counts[number] += 1
        else:
            winning_counts[number] = 1
    return winning_counts

winning_numbers_count = count_winning_numbers(roulette)

# Display the counts of winning numbers
for number, count in winning_numbers_count.items():
    print(f"The number {number} has won {count} times.")

Practity
We will be happy to hear your thoughts

Leave a reply

Python and Excel Projects for Practice
Register New Account
Shopping cart