3.2. Numeric Float

  • Represents floating point number (vide IEEE-754)

  • Could be both signed and unsigned

  • Default float size is 64 bit

  • Python automatically extends float when need bigger number

>>> data = 1.0
>>> data = +1.0
>>> data = -1.0

Floating-point numbers are not real numbers, so the result of 1.0/3.0 cannot be represented exactly without infinite precision. In the decimal (base 10) number system, one-third is a repeating fraction, so it has an infinite number of digits. Even simple non-repeating decimal numbers can be a problem. One-tenth (0.1) is obviously non-repeating, so we can express it exactly with a finite number of digits. As it turns out, since numbers within computers are stored in binary (base 2) form, even one-tenth cannot be represented exactly with floating-point numbers.

When should you use integers and when should you use floating-point numbers? A good rule of thumb is this: use integers to count things and use floating-point numbers for quantities obtained from a measuring device. As examples, we can measure length with a ruler or a laser range finder; we can measure volume with a graduated cylinder or a flow meter; we can measure mass with a spring scale or triple-beam balance. In all of these cases, the accuracy of the measured quantity is limited by the accuracy of the measuring device and the competence of the person or system performing the measurement. Environmental factors such as temperature or air density can affect some measurements. In general, the degree of inexactness of such measured quantities is far greater than that of the floating-point values that represent them.

Despite their inexactness, floating-point numbers are used every day throughout the world to solve sophisticated scientific and engineering problems. The limitations of floating-point numbers are unavoidable since values with infinite characteristics cannot be represented in a finite way. Floating-point numbers provide a good trade-off of precision for practicality.

Note

Source [1]

3.2.1. Without Zero Notation

  • .1 - notation without leading zero (0.1)

  • 1. - notation without trailing zero (1.0)

  • Used by numpy

Leading zero:

>>> data = .1
>>> print(data)
0.1

Trailing zero:

>>> data = 1.
>>> print(data)
1.0

3.2.2. Engineering Notation

  • The exponential is a number divisible by 3

  • Allows the numbers to explicitly match their corresponding SI prefixes

  • 1e3 is equal to 1000.0 (kilo)

  • 1e-3 is equal to 0.001 (milli)

Table 3.1. Engineering notation

Name

Symbol

Base

Value

yotta

Y

1e24

1000000000000000000000000.0

zetta

Z

1e21

1000000000000000000000.0

exa

E

1e18

1000000000000000000.0

peta

P

1e15

1000000000000000.0

tera

T

1e12

1000000000000.0

giga

G

1e9

1000000000.0

mega

M

1e6

1000000.0

kilo

k

1e3

1000.0

1e0

1.0

milli

m

1e−3

0.001.0

micro

μ

1e−6

0.000001.0

nano

n

1e−9

0.000000001.0

pico

p

1e−12

0.000000000001.0

femto

f

1e−15

0.000000000000001.0

atto

a

1e−18

0.000000000000000001.0

zepto

z

1e−21

0.000000000000000000001.0

yocto

y

1e−24

0.000000000000000000000001.0

You can use both lower e or uppercase letter E:

>>> x = 1e3
>>> print(x)
1000.0
>>>
>>> x = 1E3
>>> print(x)
1000.0

Both negative and positive numbers are supported:

>>> x = +1e3
>>> print(x)
1000.0
>>>
>>> x = -1e3
>>> print(x)
-1000.0

Both negative and positive exponents are supported:

>>> x = 1e3
>>> print(x)
1000.0
>>>
>>> x = 1e-3
>>> print(x)
0.001

3.2.3. Scientific notation

  • 1.23e3 is equal to 1230.0

  • 1.23e-3 is equal to 1.23e-3

>>> 1.23e3
1230.0
>>>
>>> 1.23e-3
0.00123

For numbers below 4 decimal places, Python will use notation automatically:

>>> 1.23e-4
0.000123
>>>
>>> 1.23e-5
1.23e-05

Both negative and positive numbers are supported:

>>> 1.23e3
1230.0
>>>
>>> -1.23e3
-1230.0
>>>
>>> 1.23e-3
0.00123
>>>
>>> -1.23e-3
-0.00123

3.2.4. Type Conversion

  • float(object) - converts object to float

Builtin function float() converts argument to float

>>> float(1)
1.0
>>>
>>> float(1.0)
1.0
>>>
>>> float('1.0')
1.0
>>> float('+1.0')
1.0
>>>
>>> float('-1.0')
-1.0

3.2.5. Thousand separator

  • Underscore (_) can be used as a thousand separator

>>> float('10000')
10000
>>>
>>> float('10_000')
10000

3.2.6. Decimal Separator

  • 1.0 - Decimal point

  • 1,0 - Decimal comma

  • 0٫‎1 - Arabic decimal separator (Left to right)

  • More information: [2]

../../_images/l10n-decimal-separator.png
>>> data = 1.0
>>> type(data)
<class 'float'>
>>>
>>> data = 1,0
>>> type(data)
<class 'tuple'>
>>> float('1.0')
1.0
>>>
>>> float('1,0')
Traceback (most recent call last):
ValueError: could not convert string to float: '1,0'

3.2.7. Round Number

  • round(number, ndigits) - Round a number to n decimal places

>>> pi = 3.14159265359
>>>
>>>
>>> round(pi, 4)
3.1416
>>>
>>> round(pi, 2)
3.14
>>>
>>> round(pi)
3
>>>
>>> round(pi, 0)
3.0

Rounding a number in string formatting:

>>> pi = 3.14159265359
>>>
>>>
>>> print(f'Pi number is {pi}')
Pi number is 3.14159265359
>>>
>>> print(f'Pi number is {pi:f}')
Pi number is 3.141593
>>>
>>> print(f'Pi number is {pi:.4f}')
Pi number is 3.1416
>>>
>>> print(f'Pi number is {pi:.2f}')
Pi number is 3.14
>>>
>>> print(f'Pi number is {pi:.0f}')
Pi number is 3
>>> round(10.5)
10
>>>
>>> round(10.51)
11

3.2.8. Further Reading

3.2.9. References

3.2.10. Assignments

"""
* Assignment: Type Float Tax
* Type: class assignment
* Complexity: easy
* Lines of code: 3 lines
* Time: 3 min

English:
    1. Cost of the service is 1013.25 PLN net
    2. Service has value added tax (VAT) rate of 23%
    3. Calculate gross values (with tax)
    4. Run doctests - all must succeed

Polish:
    1. Cena usługi wynosi 1013.25 PLN netto
    2. Usługa objęta jest 23% stawką VAT
    3. Oblicz cenę brutto (z podatkiem)
    4. Uruchom doctesty - wszystkie muszą się powieść

Tests:
    >>> import sys; sys.tracebacklimit = 0
    >>> from pprint import pprint

    >>> assert result is not Ellipsis, \
    'Assign your result to variable `result`'
    >>> assert type(result) is float, \
    'Variable `result` has invalid type, should be float'

    >>> result = round(result, 2)
    >>> pprint(result)
    1246.3
"""

PERCENT = 100
VAT_23 = 1.23

PLN = 1
PRICE = 1013.25 * PLN

# Gross is net plus tax in PLN
# type: float
result = ...


"""
* Assignment: Type Float Tax
* Type: class assignment
* Complexity: easy
* Lines of code: 1 lines
* Time: 2 min

English:
    1. Price of the service is 100.00 USD
    2. Define `result: float` with price in cents
    3. Run doctests - all must succeed

Polish:
    1. Cena usługi wynosi 100.00 USD
    2. Zdefiniuj `result: float` ceną w centach
    3. Uruchom doctesty - wszystkie muszą się powieść

Tests:
    >>> import sys; sys.tracebacklimit = 0
    >>> from pprint import pprint

    >>> assert result is not Ellipsis, \
    'Assign your result to variable `result`'
    >>> assert type(result) is float, \
    'Variable `result` has invalid type, should be float'

    >>> pprint(result)
    10000.0
"""

DOLLAR = 1
CENT = DOLLAR / 100

PRICE = 100*DOLLAR

# PRICE in US cents
# type: float
result = ...

"""
* Assignment: Type Float Tax
* Type: class assignment
* Complexity: easy
* Lines of code: 4 lines
* Time: 3 min

English:
    1. Cost of the service is 100.00 EUR
    2. Calculate price in Polish Zloty PLN (PLN)
    3. Calculate price in US Dollars (USD)
    4. Calculate price in Australian Dollars (AUD)
    5. Calculate price in Canadian Dollars (CAD)
    3. Run doctests - all must succeed

Polish:
    1. Cena usługi wynosi 100.00 EUR
    2. Oblicz kwotę w polskich złotych (PLN)
    3. Oblicz kwotę w dolarach amerykańskich (USD)
    4. Oblicz kwotę w dolarach australijskich (AUD)
    5. Oblicz kwotę w dolarach kanadyjskich (CAD)
    3. Uruchom doctesty - wszystkie muszą się powieść

Tests:
    >>> import sys; sys.tracebacklimit = 0
    >>> from pprint import pprint

    >>> assert result_a is not Ellipsis, \
    'Assign your result to variable `result_a`'
    >>> assert type(result_a) is float, \
    'Variable `result_a` has invalid type, should be float'

    >>> assert result_b is not Ellipsis, \
    'Assign your result to variable `result_b`'
    >>> assert type(result_b) is float, \
    'Variable `result_b` has invalid type, should be float'

    >>> assert result_c is not Ellipsis, \
    'Assign your result to variable `result_c`'
    >>> assert type(result_c) is float, \
    'Variable `result_c` has invalid type, should be float'

    >>> assert result_d is not Ellipsis, \
    'Assign your result to variable `result_d`'
    >>> assert type(result_d) is float, \
    'Variable `result_d` has invalid type, should be float'

    >>> result = round(result_a, 1)
    >>> pprint(result)
    435.0

    >>> result = round(result_b, 1)
    >>> pprint(result)
    110.0

    >>> result = round(result_c, 1)
    >>> pprint(result)
    166.0

    >>> result = round(result_d, 1)
    >>> pprint(result)
    149.0
"""

EUR = 1
PLN = EUR / 4.35
USD = EUR / 1.10
AUD = EUR / 1.66
CAD = EUR / 1.49

PRICE = 100*EUR

# PRICE in Polish Zloty PLN (PLN)
# type: float
result_a = ...

# PRICE in US Dollars (USD)
# type: float
result_b = ...

# PRICE in Australian Dollars (AUD)
# type: float
result_c = ...

# PRICE in Canadian Dollars (CAD)
# type: float
result_d = ...

"""
* Assignment: Type Float Tax
* Type: class assignment
* Complexity: easy
* Lines of code: 1 lines
* Time: 3 min

English:
    1. Cost of the service is 1000.00 PLN net
    2. Service has value added tax (VAT) rate of 23%
    3. Calculate VAT tax
    4. Run doctests - all must succeed

Polish:
    1. Cena usługi wynosi 1000.00 PLN netto
    2. Usługa objęta jest 23% stawką VAT
    3. Oblicz wartości podatku VAT
    4. Uruchom doctesty - wszystkie muszą się powieść

Tests:
    >>> import sys; sys.tracebacklimit = 0
    >>> from pprint import pprint

    >>> assert result is not Ellipsis, \
    'Assign your result to variable `result`'
    >>> assert type(result) is float, \
    'Variable `result` has invalid type, should be float'

    >>> pprint(result)
    230.0
"""

PLN = 1.00
VAT_23 = 0.23

PRICE = 1000.00*PLN

# VAT tax for 1000.00 PLN net price
# type: float
result = ...

"""
* Assignment: Type Float Altitude
* Type: class assignment
* Complexity: easy
* Lines of code: 2 lines
* Time: 3 min

English:
    1. Plane altitude is 10 km
    2. Convert to feet (ft) in imperial system (US)
    3. Convert to meters (m) in metric system (SI)
    4. Run doctests - all must succeed

Polish:
    1. Wysokość lotu samolotem wynosi 10 km
    2. Przelicz je na stopy (ft) w systemie imperialnym (US)
    3. Przelicz je na metry (m) w systie metrycznym (układ SI)
    4. Uruchom doctesty - wszystkie muszą się powieść

Tests:
    >>> import sys; sys.tracebacklimit = 0
    >>> from pprint import pprint

    >>> assert altitude_m is not Ellipsis, \
    'Assign your result to variable `altitude_m`'
    >>> assert altitude_ft is not Ellipsis, \
    'Assign your result to variable `altitude_ft`'
    >>> assert type(altitude_m) is float, \
    'Variable `altitude_m` has invalid type, should be float'
    >>> assert type(altitude_ft) is float, \
    'Variable `altitude_ft` has invalid type, should be float'

    >>> result = round(altitude_m, 1)
    >>> pprint(result)
    10000.0

    >>> result = round(altitude_ft, 1)
    >>> pprint(result)
    32808.4
"""

m = 1
km = 1000 * m
ft = 0.3048 * m

ALTITUDE = 10*km


# ALTITUDE in meters
# type: float
altitude_m = ...

# ALTITUDE in feet
# type: float
altitude_ft = ...

3.2.11. Homework

"""
* Assignment: Type Float Volume
* Type: class assignment
* Complexity: easy
* Lines of code: 2 lines
* Time: 3 min

English:
    1. Bottle volume is 500 mililiter
    2. Convert to fluid unces (floz) in imperial system (US)
    3. Convert to liters (liter) in metric system (SI)
    4. Run doctests - all must succeed

Polish:
    1. Objętość butelki wynosi 500 mililitrów
    2. Przelicz je na uncje płynu (floz) w systemie imperialnym (US)
    3. Przelicz je na litry (liter) w systie metrycznym (układ SI)
    4. Uruchom doctesty - wszystkie muszą się powieść

Tests:
    >>> import sys; sys.tracebacklimit = 0
    >>> from pprint import pprint

    >>> assert volume_floz is not Ellipsis, \
    'Assign your result to variable `volume_floz`'
    >>> assert volume_l is not Ellipsis, \
    'Assign your result to variable `volume_l`'
    >>> assert type(volume_floz) is float, \
    'Variable `volume_floz` has invalid type, should be float'
    >>> assert type(volume_l) is float, \
    'Variable `volume_l` has invalid type, should be float'

    >>> result = round(volume_floz, 1)
    >>> pprint(result)
    16.9

    >>> result = round(volume_l, 1)
    >>> pprint(result)
    0.5
"""

liter = 1
milliliter = 0.001 * liter
floz = 0.02957344 * liter

VOLUME = 500 * milliliter

# VOLUME in fluid ounces
# type: float
volume_floz = ...

# VOLUME in liters
# type: float
volume_l = ...

../../_images/type-float-spacesuits.png

Figure 3.1. EMU and Orlan

"""
* Assignment: Type Float Round
* Type: class assignment
* Complexity: easy
* Lines of code: 4 lines
* Time: 5 min

English:
    1. Euler's number is 2.71828
    2. Round number using `round()` funtion
    3. Run doctests - all must succeed

Polish:
    1. Liczba Eulra to 2.71828
    2. Zaokrąglij liczbę wykorzystując funkcję `round()`
    3. Uruchom doctesty - wszystkie muszą się powieść

Tests:
    >>> import sys; sys.tracebacklimit = 0
    >>> from pprint import pprint

    >>> assert a is not Ellipsis, \
    'Assign your result to variable `a`'
    >>> assert b is not Ellipsis, \
    'Assign your result to variable `b`'
    >>> assert c is not Ellipsis, \
    'Assign your result to variable `c`'
    >>> assert d is not Ellipsis, \
    'Assign your result to variable `d`'
    >>> assert e is not Ellipsis, \
    'Assign your result to variable `e`'

    >>> assert type(a) is float, \
    'Variable `a` has invalid type, should be float'
    >>> assert type(b) is float, \
    'Variable `b` has invalid type, should be float'
    >>> assert type(c) is float, \
    'Variable `c` has invalid type, should be float'
    >>> assert type(d) is float, \
    'Variable `d` has invalid type, should be float'
    >>> assert type(e) is int, \
    'Variable `e` has invalid type, should be int'

    >>> pprint(a)
    2.718

    >>> pprint(b)
    2.72

    >>> pprint(c)
    2.7

    >>> pprint(d)
    3.0

    >>> pprint(e)
    3

"""

EULER = 2.71828

# Round Euler's number to 3 decimal places
# Use `round()`
# type: float
a = ...

# Round Euler's number to 2 decimal places
# Use `round()`
# type: float
b = ...

# Round Euler's number to 1 decimal places
# Use `round()`
# type: float
c = ...

# Round Euler's number to 0 decimal places
# Use `round()`
# type: float
d = ...

# Round Euler's number to nearest integer
# Use `round()`
# type: int
e = ...

"""
* Assignment: Type Float Round
* Type: class assignment
* Complexity: easy
* Lines of code: 4 lines
* Time: 5 min

English:
    1. Euler's number is 2.71828
    2. Round number using f-string formatting,
       example: f'{number:.2f}'
    3. Run doctests - all must succeed

Polish:
    1. Liczba Eulra to 2.71828
    2. Zaokrąglij liczbę wykorzystując formatowanie f-string,
       przykład: f'{liczba:.2f}'
    3. Uruchom doctesty - wszystkie muszą się powieść

Tests:
    >>> import sys; sys.tracebacklimit = 0
    >>> from pprint import pprint

    >>> assert a is not Ellipsis, \
    'Assign your result to variable `a`'
    >>> assert b is not Ellipsis, \
    'Assign your result to variable `b`'
    >>> assert c is not Ellipsis, \
    'Assign your result to variable `c`'
    >>> assert d is not Ellipsis, \
    'Assign your result to variable `d`'

    >>> assert type(a) is str, \
    'Variable `a` has invalid type, should be str'
    >>> assert type(b) is str, \
    'Variable `b` has invalid type, should be str'
    >>> assert type(c) is str, \
    'Variable `c` has invalid type, should be str'
    >>> assert type(d) is str, \
    'Variable `d` has invalid type, should be str'

    >>> pprint(a)
    'Result: 2.718'

    >>> pprint(b)
    'Result: 2.72'

    >>> pprint(c)
    'Result: 2.7'

    >>> pprint(d)
    'Result: 3'

"""

EULER = 2.71828

# Round Euler's number to 3 decimal places
# Round number using f-string formatting
# type: str
a = f"Result: {EULER}"

# Round Euler's number to 2 decimal places
# Round number using f-string formatting
# type: str
b = f"Result: {EULER}"

# Round Euler's number to 1 decimal places
# Round number using f-string formatting
# type: str
c = f"Result: {EULER}"

# Round Euler's number to 0 decimal places
# Round number using f-string formatting
# type: str
d = f"Result: {EULER}"

"""
* Assignment: Type Float Velocity
* Type: class assignment
* Complexity: easy
* Lines of code: 2 lines
* Time: 3 min

English:
    1. Speed limit is 75 MPH
    2. Convert to miles per hour (mph) in imperial system (US)
    3. Convert to kilometers per hour (kph) in metric system (SI)
    4. Speed limit print in KPH (km/h)
    5. Run doctests - all must succeed

Polish:
    1. Ograniczenie prędkości wynosi 75 MPH
    2. Przelicz je na mile na godzinę (mph) w systemie imperialnym (US)
    3. Przelicz je na kilometry na godzinę (kph) w systie metrycznym (układ SI)
    4. Ograniczenie prędkości wypisz w KPH (km/h)
    5. Uruchom doctesty - wszystkie muszą się powieść

Tests:
    >>> import sys; sys.tracebacklimit = 0
    >>> from pprint import pprint

    >>> assert speed_limit_mph is not Ellipsis, \
    'Assign your result to variable `speed_limit_mph`'
    >>> assert speed_limit_kph is not Ellipsis, \
    'Assign your result to variable `speed_limit_kph`'
    >>> assert type(speed_limit_mph) is float, \
    'Variable `speed_limit_mph` has invalid type, should be float'
    >>> assert type(speed_limit_kph) is float, \
    'Variable `speed_limit_kph` has invalid type, should be float'

    >>> result = round(speed_limit_mph, 1)
    >>> pprint(result)
    75.0

    >>> result = round(speed_limit_kph, 1)
    >>> pprint(result)
    120.7

"""

SECOND = 1
MINUTE = 60 * SECOND
HOUR = 60 * MINUTE

m = 1
km = 1000 * m
mi = 1609.344 * m
kph = km / HOUR
mph = mi / HOUR

SPEED_LIMIT = 75 * mph


# SPEED_LIMIT in miles per hour
# type: float
speed_limit_mph = ...

# SPEED_LIMIT in kilometers per hour
# type: float
speed_limit_kph = ...

"""
* Assignment: Type Float Pressure
* Type: homework
* Complexity: medium
* Lines of code: 2 lines
* Time: 3 min

English:
    1. Operational pressure of EMU spacesuit: 4.3 PSI
    2. Operational pressure of ORLAN spacesuit: 40 kPa
    3. Calculate operational pressure in hPa for EMU
    4. Calculate operational pressure in hPa for Orlan
    5. Run doctests - all must succeed

Polish:
    1. Ciśnienie operacyjne skafandra kosmicznego EMU (NASA): 4.3 PSI
    2. Ciśnienie operacyjne skafandra kosmicznego ORLAN (Roscosmos): 40 kPa
    3. Oblicz ciśnienie operacyjne skafandra EMU w hPa
    4. Oblicz ciśnienie operacyjne skafandra Orlan w hPa
    5. Uruchom doctesty - wszystkie muszą się powieść

Tests:
    >>> import sys; sys.tracebacklimit = 0

    >>> assert emu is not Ellipsis, \
    'Assign your result to variable `emu`'
    >>> assert orlan is not Ellipsis, \
    'Assign your result to variable `orlan`'
    >>> assert type(emu) is float, \
    'Variable `emu` has invalid type, should be float'
    >>> assert type(orlan) is float, \
    'Variable `orlan` has invalid type, should be float'

    >>> round(orlan, 1)
    400.0
    >>> round(emu, 1)
    296.5
"""

Pa = 1
hPa = 100 * Pa
kPa = 1000 * Pa
psi = 6894.757 * Pa

# 4.3 pounds per square inch in hectopascals
# type: float
emu = ...

# 40 kilopascals in hectopascals
# type: float
orlan = ...

"""
* Assignment: Type Float Percent
* Type: homework
* Complexity: medium
* Lines of code: 2 lines
* Time: 3 min

English:
    1. Pressure in International Standard Atmosphere (ISA)
       at sea level is: 1 ata = 1013.25 hPa
    2. Calculate `pO2` - partial pressure of oxygen at sea level in hPa
    3. To calculate partial pressure use ratio
          100% --- 1013.25 hPa
       20.946% --- ? hPa
    4. Run doctests - all must succeed

Polish:
    1. Ciśnienie w Międzynarodowej Standardowej Atmosfera (ISA)
       na poziomie morza wynosi: 1 ata = 1013.25 hPa
    2. Oblicz `pO2` - ciśnienie parcjalne tlenu na poziomie morza w hPa
    3. Aby policzyć ciśnienie parcjalne skorzystaj z proporcji
          100% --- 1013.25 hPa
       20.946% --- ? hPa
    4. Uruchom doctesty - wszystkie muszą się powieść

Hints:
    * 1 hPa = 100 Pa
    * 1 kPa = 1000 Pa
    * 1 ata = 1013.25 hPa
    * ISA - International Standard Atmosphere
    * Atmosphere gas composition:
        * Nitrogen 78.084%
        * Oxygen 20.946%
        * Argon 0.9340%
        * Carbon Dioxide 0.0407%
        * Others 0.001%

Tests:
    >>> import sys; sys.tracebacklimit = 0

    >>> assert ata is not Ellipsis, \
    'Assign your result to variable `ata`'
    >>> assert type(ata) is float, \
    'Variable `ata` has invalid type, should be float'

    >>> assert pO2 is not Ellipsis, \
    'Assign your result to variable `pO2`'
    >>> assert type(pO2) is float, \
    'Variable `pO2` has invalid type, should be float'

    >>> ata
    101325.0
    >>> round(pO2, 1)
    212.2
"""

PERCENT = 100
N2 = 78.084 / PERCENT
O2 = 20.946 / PERCENT
Ar = 0.9340 / PERCENT
CO2 = 0.0407 / PERCENT
Others = 0.001 / PERCENT

Pa = 1
hPa = 100 * Pa
kPa = 1000 * Pa

# Pressure in ISA at sea level is: 1 ata = 1013.25 hPa
# type: float
ata = ...

# 20.946% of pressure at sea level in hPa
# type: float
pO2 = ...

"""
* Assignment: Type Float Gradient
* Type: homework
* Complexity: medium
* Lines of code: 2 lines
* Time: 3 min

English:
    1. At what altitude above sea level, pressure is equal
       to partial pressure of oxygen
    2. Print result in meters rounding to two decimal places
    3. To calculate partial pressure use ratio
       (100% is 1013.25 hPa, 20.946% is how many hPa?)
    4. Calculated altitude is pressure at sea level minus
       oxygen partial pressure divided by gradient
    5. Mind the operator precedence
    6. Run doctests - all must succeed

Polish:
    1. Na jakiej wysokości nad poziomem morza panuje ciśnienie
       równe ciśnieniu parcjalnemu tlenu?
    2. Wypisz rezultat w metrach zaokrąglając do dwóch miejsc po przecinku
    3. Aby policzyć ciśnienie parcjalne skorzystaj z proporcji
       (100% to 1013.25 hPa, 20.946% to ile hPa?)
    4. Wyliczona wysokość to ciśnienie atmosferyczne na poziomie morza minus
       ciśnienie parcjalne tlenu podzielone przez gradient
    5. Zwróć uwagę na kolejność wykonywania działań
    6. Uruchom doctesty - wszystkie muszą się powieść

Hints:
    * pressure gradient (decrease) = 11.3 Pa / 1 m
    * 1 hPa = 100 Pa
    * 1 kPa = 1000 Pa
    * 1 ata = 1013.25 hPa (ISA - International Standard Atmosphere)
    * Atmosphere gas composition:
        * Nitrogen 78.084%
        * Oxygen 20.946%
        * Argon 0.9340%
        * Carbon Dioxide 0.0407%
        * Others 0.001%

Tests:
    >>> import sys; sys.tracebacklimit = 0

    >>> assert gradient is not Ellipsis, \
    'Assign your result to variable `gradient`'
    >>> assert type(gradient) is float, \
    'Variable `gradient` has invalid type, should be float'

    >>> assert altitude is not Ellipsis, \
    'Assign your result to variable `altitude`'
    >>> assert type(altitude) is float, \
    'Variable `altitude` has invalid type, should be float'

    >>> pO2
    21223.5345
    >>> gradient
    11.3
    >>> round(altitude/m, 2)
    7088.63
"""

PERCENT = 100
N2 = 78.084 / PERCENT
O2 = 20.946 / PERCENT
Ar = 0.9340 / PERCENT
CO2 = 0.0407 / PERCENT
Others = 0.001 / PERCENT

m = 1
Pa = 1
hPa = 100 * Pa
ata = 1013.25 * hPa
pO2 = O2 * ata

# 11.3 Pascals per meter
# type: float
gradient = ...

# Altitude is ata minus pO2 all that divided by gradient
# type: float
altitude = ...