This Python program reads up to 10 integers and for each number reports:
- How many times it occurs
- At which positions (1-based index) it appears
def analyze_numbers(numbers: list[int]):
info = {}
for idx, num in enumerate(numbers, start=1):
if num not in info:
info[num] = {"count": 0, "positions": []}
info[num]["count"] += 1
info[num]["positions"].append(idx)
for num in sorted(info.keys()):
count = info[num]["count"]
positions = " ".join(map(str, info[num]["positions"]))
print(f"{num} OCCURS {count} TIMES, AT POSITIONS {positions}")
# Read input from user
raw_input = input("Enter up to 10 numbers separated by space: ")
numbers = list(map(int, raw_input.strip().split()))
if len(numbers) > 10:
print("Only 10 numbers are allowed.")
else:
analyze_numbers(numbers)
Input: 13 14 13 12 14 12 13 14 12 13
Output:
12 OCCURS 3 TIMES, AT POSITIONS 4 6 9
13 OCCURS 4 TIMES, AT POSITIONS 1 3 7 10
14 OCCURS 3 TIMES, AT POSITIONS 2 5 8