# Playing with Sets and Probability
In this chapter, we’ll start by learning how
we can make our programs understand and
manipulate sets of numbers. We’ll then see how
sets can help us understand basic concepts in prob-
ability. Finally, we’ll learn about generating random
numbers to simulate random events. Let’s get started!

---

## Set Construction
In mathematical notation, you represent a set by writing the set members
enclosed in curly brackets. For example, {2, 4, 6} represents a set with 2, 4,
and 6 as its members. To create a set in Python, we can use the FiniteSet
class from the sympy package, as follows:


```python
from sympy import FiniteSet
s = FiniteSet(2,4,6)
s
```




$\displaystyle \left\{2, 4, 6\right\}$




```python
from sympy import FiniteSet
from fractions import Fraction
s = FiniteSet(1, 1.5, Fraction(1, 5))

print("Set is:" + str(s) + " and its length is:" + str(len(s)))
```

    Set is:FiniteSet(1/5, 1, 1.5) and its length is:3


e9761c6f7297eff294a8e5dafea90f8bb395933e
ipynb
Jupyter Notebook
2021/Python-Maths/chapter5.ipynb
Muramatsu2602/python-study
c81eb5d2c343817bc29b2763dcdcabed0f6a42c6
MIT
2021/Python-Maths/chapter5.ipynb
Muramatsu2602/python-study
c81eb5d2c343817bc29b2763dcdcabed0f6a42c6
MIT
2021/Python-Maths/chapter5.ipynb
Muramatsu2602/python-study
c81eb5d2c343817bc29b2763dcdcabed0f6a42c6
MIT
Qwen/Qwen-72B
1. YES
2. YES