3. Float numbers

3.1. Defining

>>> net_salary = 8000.63
>>> print(net_salary)
8000.63

3.2. Checking type

>>> type(net_salary)
<class 'float'>

3.3. Type conversion

>>> salary_converted = int(net_salary)
>>> salary_converted == net_salary
False

3.4. Interesting facts

>>> print(0.1 + 0.2)
0.30000000000000004

Hint

Answer on the page.

Additional wiki page about IEEE 754.

import decimal

ctx = decimal.getcontext()
print(ctx)

a = decimal.Decimal(0.2)
b = decimal.Decimal(0.1)

ctx.prec = 6
print(a + b)

3.5. Exercise

  1. Calculate sum of 123, 321, 675 and print result on the screen,

  2. Check if sum is multiples of the number 5,

  3. Calculate income tax (tax rate is 19%) user is giving the amount (input). Assuming tax free allowance is 5000,

  4. Calculate area of circle (with given radius by the user)

Hint

Use input function. You may also import additional module - search for it using google