Why the following code is false? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
5th Jan 2020, 9:51 AM
Anas Sanba
3 Answers
+ 6
Run it like this and you will see the difference: from math import e ,log print(e**log(2))
5th Jan 2020, 10:00 AM
Paul
Paul - avatar
+ 5
because it's a float value you get from e**log(2) which is an aproximation but not exact. when using == you test if the two numbers are exactly the same to get to true you have to either round the result or check if the difference between the two values is very small
5th Jan 2020, 10:04 AM
Anton Böhler
Anton Böhler - avatar
+ 2
Thx ❤️ ❤️
5th Jan 2020, 10:12 AM
Anas Sanba