educative.io

Multiplication operators

print(10.2 * 3) = 30.599999999999998
why not 30.6


Course: Learn Python 3 from Scratch - Free Interactive Course
Lesson: Arithmetic Operators - Learn Python 3 from Scratch

Hi @Uzma
This is the difference between python versions. In python2, we can get 30.6 and in python3, we get 30.599999999999998.
You can use the format function to make this result exactly 30.6.
print(format(10.2*3,“0.1f”))