Converting to Floating Point in Python

To convert to a floating point number, use the float function.

Let's apply this function to a string:

pythontxt = '12.1'
print(float(txt)) # 12.0

Now to the whole number:

pythonnum = 12
print(float(num)) # 12.0

After the transformation, we can perform mathematical operations on our variables:

pythontest1 = '1.1'
test2 = '2.1'

test3 = float(test1) + float(test2)
print(test3) # 3.2
Задание 1

Given variables:

pythontst1 = '1.1'
tst2 = '1.2'

Find the sum of the values ​​of these variables.

Задание 2

Given variables:

pythontst1 = 2
tst2 = 4

Convert them to floating point numbers and find their difference.