About the program
This Python program reads 5 numbers and stores them in an array.
It then reads another number and reports how many times it appears in the array and at which positions (indexes 1 to 5).
Python code:
def find_occurrences(arr: list[int], target: int) -> tuple[int, list[int]]:
positions = []
for idx, val in enumerate(arr, start=1):
if val == target:
positions.append(idx)
return len(positions), positions
# Read 5 numbers from the user
raw_input = input("Enter 5 numbers separated by spaces: ")
numbers = list(map(int, raw_input.strip().split()))
if len(numbers) != 5:
print("You must enter exactly 5 numbers.")
else:
x = int(input("Enter the number to look for: "))
count, positions = find_occurrences(numbers, x)
print(f"{x} → appears {count} time(s).")
if positions:
print(f"Positions: {' '.join(map(str, positions))}")
else:
print("This number is not in the array.")Sample output:
Input: 7 3 7 1 7
Number to look for: 7
Output:
7 → appears 3 time(s).
Positions: 1 3 5