Part of the series

Several example codes

~1 min read • Updated Oct 13, 2025

Program Overview

This Python program reads 10 numbers from input, stores them in an array, and counts how many times each number appears.
It uses a dictionary to track frequencies.


Python Code:


def count_frequencies(arr: list[int]) -> dict[int, int]:
    freq = {}
    for num in arr:
        freq[num] = freq.get(num, 0) + 1
    return freq

# Read input from user
raw_input = input("Enter 10 numbers separated by space: ")
numbers = list(map(int, raw_input.strip().split()))

if len(numbers) != 10:
    print("You must enter exactly 10 numbers.")
else:
    frequencies = count_frequencies(numbers)
    print("Frequency of each number:")
    for num in sorted(frequencies.keys()):
        print(f"{num} → {frequencies[num]} times")

Sample Output:


Input: 5 3 5 2 3 5 1 2 3 5  
Output:  
1 → 1 times  
2 → 2 times  
3 → 3 times  
5 → 4 times

Written & researched by Dr. Shahin Siami