+ 1
Why Python division it's so bad?
The regular division operator on python (/) its very bad, sometimes just gives wrong values. I was doing the test for the 4th chapter of Python for beginners and was stuck like half an hour because I was thinking that it was something wrong with my code but it wasn't, and then just tried to change "/" for "//" and it worked just fine đ€Šđ»ââïžđ€Šđ»ââïžđ€Šđ»ââïžđ€Šđ»ââïž
10 Respostas
+ 10
Juan Manuel GonzĂĄlez Vega
if you post a link to your code and a proper task description we can see what issue you have, and we may help you.
+ 5
/ and // are different. Read the lesson again and check comments to understand it better.
+ 5
Your code should look like this:
if imc < 18.5:
print("Underweight")
elif imc < 25:
print("Normal")
elif imc < 30:
print("Overweight")
else:
print("Obesity")
Why the 24.9 and the 29.9? Why not 25 and 30?
+ 5
It is strange that it is different, I have seen more people using 24.9 and 29.9, but I couldn't understand why. Thanks for showing it. I think the English version is more logical.
+ 4
Might be there u need to print output in integer form not floating point number.
So read input output formats and constraints
+ 3
This is the exercise text. I don't see 24.9 nor 29.9.
The resulting number indicates one of the following categories:
Underweight = less than 18.5
Normal = more or equal to 18.5 and less than 25
Overweight = more or equal to 25 and less than 30
Obesity = 30 or more
+ 2
peso = input()
altura = input()
try:
imc = float(peso) / (float(altura) **2)
except:
print("Invalid Input")
if imc < 18.5:
print("Underweight")
elif imc < 24.9:
print("Normal")
elif imc < 29.9:
print("Overweight")
elif imc >= 30:
print("Obesity")
#That was my code, when I use // instead of / on the line 4 it works just fine
+ 2
Well mine looks different, that's weird, it's in Spanish but you can translate it:
El nĂșmero resultante indica una de las siguientes categorĂas:
Underweight = menos de 18.5
Normal = 18.5 - 24.9
Overweight = 25 - 29.9
Obesity = 30 o mĂĄs
That's what it says đ€·đ»ââïž
+ 2
Yeah true English seems more logical đ
0
The numbers are like that because that's what the exercise said, I just do it the way they were asking đ€·đ»ââïž