-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzad16.py
More file actions
31 lines (24 loc) · 1.03 KB
/
zad16.py
File metadata and controls
31 lines (24 loc) · 1.03 KB
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
31
# Utwórz dwa zbiory i wypełnij je kilkoma losowymi liczbami
# całkowitymi z dowolnego przedziału, np. od 1 do 10 (przedział
# nie powinien być zbyt szeroki, żeby zbiory mogły mieć jakąś
# część wspólną). Następnie wypisz ich: sumę, różnicę i część
# wspólną, a także te elementy, które pojawiają się tylko w
# jednym z nich.
import random
set1, set2 = set(), set()
for i in range(5):
set1.add(random.randint(1, 10))
set2.add(random.randint(1, 10))
def sumOfSets(set1: set, set2: set):
return set1.union(set2)
def setsDiff(set1: set, set2: set):
return set1.difference(set2)
def setsIntersection(set1: set, set2: set):
return set1.intersection(set2)
print(f"Zbiór A: {set1}")
print(f"Zbiór B: {set2}")
print(f"Suma zbiorów: {sumOfSets(set1, set2)}")
print(f"Symetryczna różnica zbiorów: {set1.symmetric_difference(set2)}")
print(f"Różnica zbiorów A\B: {setsDiff(set1, set2)}")
print(f"Różnica zbiorów B\A: {setsDiff(set2, set1)}")
print(f"Część wspólna zbiorów: {setsIntersection(set1, set2)}")