Please where do i get a mistake here ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Please where do i get a mistake here ?

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

22nd Sep 2023, 2:09 AM
SAGIR ISAH
SAGIR ISAH - avatar
3 Answers
+ 5
Maybe use float if the test requires all decimal values.
22nd Sep 2023, 3:42 AM
Chris Coder
Chris Coder - avatar
0
NO! The problem has nothing to do with "float" or "int" It has to be something else,
22nd Sep 2023, 6:46 AM
SAGIR ISAH
SAGIR ISAH - avatar
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.
22nd Sep 2023, 6:02 PM
Rain
Rain - avatar