# 1. Creating formulas
Write the following mathematical formula in Python:

\begin{align}
 result = 6a^3 - \frac{8b^2 }{4c} + 11
\end{align}



```python
a = 2
b = 3
c = 2
```


```python
# Your formula here:
result = 6*(a**3) - 8*(b**2)/(4*c) + 11
```


```python

assert result == 50
```

# 2. Floating point pitfalls
Show that `0.1 + 0.2 == 0.3`


```python
# Your solution here
a = 0.1
b = 0.2
c = a + 3
c

```




    3.1




```python
assert c == 0.3 #Fail, c = 3.1 because of binary floating point
```


```python
from decimal import *
Decimal(0.1) + Decimal(0.2) #Decimal('0.30') => combined total # decimal place in arithmetic calc
Decimal('0.1') + Decimal('0.2') #Decimal('0.3')

```




    Decimal('0.3')




```python
from decimal import *
getcontext().prec = 2
getcontext()
Decimal(0.1+0.2) #Decimal('0.3000000000000000444089209850062616169452667236328125')

```




    Decimal('0.3000000000000000444089209850062616169452667236328125')



4810ebaa6902e8f25ea4edfe040db8c2dcd600e5
ipynb
Jupyter Notebook
python_materials/learn-python3/notebooks/beginner/exercises/numbers_exercise.ipynb
NguyenCuuNguyen/CS488S21
7c585a40af791f34090ad6979941e23bcf1ddfa1
MIT
python_materials/learn-python3/notebooks/beginner/exercises/numbers_exercise.ipynb
NguyenCuuNguyen/CS488S21
7c585a40af791f34090ad6979941e23bcf1ddfa1
MIT
python_materials/learn-python3/notebooks/beginner/exercises/numbers_exercise.ipynb
NguyenCuuNguyen/CS488S21
7c585a40af791f34090ad6979941e23bcf1ddfa1
MIT
Qwen/Qwen-72B
1. YES
2. YES