Ответ:
import random
# Generate 5 random elements
elements1 = random.sample(range(100), 5)
elements2 = random.sample(range(100), 5)
# Create sets from the random elements
set1 = set(elements1)
set2 = set(elements2)
# Print the sets
print("Set 1:", set1)
print("Set 2:", set2)
# Create a set of non-matching elements
non_matching = set1.symmetric_difference(set2)
print("Non-matching elements:", non_matching)
# Create a set of matching elements
matching = set1.intersection(set2)
print("Matching elements:", matching)
Объяснение:
Надеюсь всё понятно.
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Ответ:
import random
# Generate 5 random elements
elements1 = random.sample(range(100), 5)
elements2 = random.sample(range(100), 5)
# Create sets from the random elements
set1 = set(elements1)
set2 = set(elements2)
# Print the sets
print("Set 1:", set1)
print("Set 2:", set2)
# Create a set of non-matching elements
non_matching = set1.symmetric_difference(set2)
print("Non-matching elements:", non_matching)
# Create a set of matching elements
matching = set1.intersection(set2)
print("Matching elements:", matching)
Объяснение:
Надеюсь всё понятно.