+ 1
Why output 100.0 ? Please check my code give me solution
3 ответов
+ 4
That is a great question!
Let's see what The Python Standard Library says about it:
"Objects of different types, except different numeric types, never compare equal."
So, we can see that two variables of numeric types can be considered equal; in this case, a integer and a float (100 and 100.0). This is why the result is 100.0.
https://docs.python.org/3/library/stdtypes.html#comparisons
+ 3
By the way, if you turn all the elif clauses into if clauses, you will see the code returning "Number is 100" as well.
+ 2
Try something like this: turn the number into a string. If it is a float, it will keep the dot and the zero.
https://code.sololearn.com/cNH5azBjSMOD/