-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRepeated_Values.py
29 lines (24 loc) · 1.02 KB
/
Repeated_Values.py
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
import random
# Function to count the repeated elements
def count_repeated_elements(my_tuple):
counts = {}
for item in my_tuple:
if item in counts:
counts[item] += 1
else:
counts[item] = 1
result = [(item, count) for item, count in counts.items() if count > 1]
return tuple(result)
# Function to generate a random tuple with specified length and range of values
def generate_random_tuple(length, min_value, max_value):
return tuple(random.randint(min_value, max_value) for _ in range(length))
repetions = int(input("How many times should this repeat? "))
start = int(input("What is the starting number? "))
end = int(input("What is the ending number? "))
# Generate a random tuple with 20 elements ranging from 1 to 100
random_tuple = generate_random_tuple(repetions + 1, start , end)
# Print the generated random tuple
print("Random Tuple:", random_tuple)
# Find and print the repeated elements
result = count_repeated_elements(random_tuple)
print("Repeated Elements:", result)