0
Please where do i get a mistake here ?
3 Answers
+ 5
Maybe use float if the test requires all decimal values.
0
NO! The problem has nothing to do with "float" or "int"
It has to be something else,
0
SAGIR ISAH ,
Change
weight_kg = int(weight_lbs) * 0.45
to
weight_kg = int(weight_lbs) * 45 / 100
If that's for a Sololearn quiz, your output has to be the exact same string as the quiz expects. Unfortunately, Python and other languages sometimes have tiny errors in the last digit when calculating floats.
For example, 99 * 0.45 comes out as 44.550000000000004
but 99 * 45 / 100 comes out as 44.55
The difference is mathematically insignificant, but it will fail Sololearn's string compare.
A good habit to avoid the tiny errors is to always multiply before you divide, so that most of the calculation is done in the integer realm.
The other way is to explicitly round your result to two decimal places (or whatever is expected) before printing. But then you have to be careful which rounding method you use. Different methods round ties (such a 0.5) toward positive infinity, toward negative infinity, away from zero, toward zero, or even to the nearest even integer.
And be polite.