0
BMI calculator
In the BMI calculator project of python beginners I get the last two hidden tests wrong, but I don't understand why. Can you help me?
8 Antworten
+ 3
We might help you if you show your attempt to us but without showing your code it's difficult to help you. So please attach the code with the code playground.
https://www.sololearn.com/post/75089/?ref=app
0
Post your attempt please
0
Is my code
0
Just some mistakes in the conditions. I have updated it and you will understand the mistakes by comparing this code with your code:
https://code.sololearn.com/ca7A141a20a1
0
# Hi I Am Noob :) ypur corrected code should be:
peso = float(input())
altura = float(input())
imc = ( peso/( altura**2 ) )
if ( 18.5 > imc ):
print("Underweight")
if ( 18.5 <= imc < 25 ):
print("Normal")
if ( 25 <= imc < 30 ):
print("Overweight")
if ( 30 <= imc ):
print("Obesity")
"""
# this could be simplified to:
if imc < 18.5:
print("Underweight")
elif imc < 25:
print("Normal")
elif imc < 30:
print("Overweight")
else:
print("Obesity")
# in python parenthesis around condition are optional
# if..elif..else allow to only test for previously untested values
# first if body is executed if imc < 18.5, so next elif..else could assume that 18.5 <= imc
# similarly for next conditions...
# that's also why final else if present do never take condition ;)
"""
- 1
#your code goes here
weight = float(input())
height = float(input())
bmi = weight / (height ** 2)
if bmi < 18.5:
print('Underweight')
elif bmi >= 18.5 and bmi < 25:
print('Normal')
elif bmi >= 25 and bmi < 30:
print('Overweight')
elif bmi >= 30:
print('Obesity')
Copy and paste my answer
If it is right please vote for me