-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmode.py
More file actions
30 lines (25 loc) · 767 Bytes
/
mode.py
File metadata and controls
30 lines (25 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Get input from the user
numbers = input("Enter numbers (Separated by Comma): ")
num_list = [int(num) for num in numbers.split(",")]
# Count occurrences
instances_count = {}
for num in num_list:
if num in instances_count:
instances_count[num] += 1
else:
instances_count[num] = 1
# Display counts
print("Count of all numbers:")
for num, count in instances_count.items():
print(f"{num}: {count}")
# Find the max count manually
max_count = 0
for count in instances_count.values():
if count > max_count:
max_count = count
# Collect all modes
modes = []
for num, count in instances_count.items():
if count == max_count:
modes.append(str(num)) # convert to string for printing
print(f"Mode(s): {', '.join(modes)}")