+ 1

Why output 100.0 ? Please check my code give me solution

https://code.sololearn.com/cYtu1M7NQIEv/?ref=app

10th Feb 2018, 5:00 AM
Hemendra Mehta
Hemendra Mehta - avatar
3 odpowiedzi
+ 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
10th Feb 2018, 5:34 AM
Pedro Maimere
Pedro Maimere - avatar
+ 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.
10th Feb 2018, 5:36 AM
Pedro Maimere
Pedro Maimere - avatar
+ 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/
10th Feb 2018, 5:44 AM
Pedro Maimere
Pedro Maimere - avatar