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:
txt = '12.1'
print(float(txt)) # 12.0
Now to the whole number:
num = 12
print(float(num)) # 12.0
After the transformation, we can perform mathematical operations on our variables:
test1 = '1.1'
test2 = '2.1'
test3 = float(test1) + float(test2)
print(test3) # 3.2
Given variables:
tst1 = '1.1'
tst2 = '1.2'
Find the sum of the values of these variables.
Given variables:
tst1 = 2
tst2 = 4
Convert them to floating point numbers and find their difference.