+ 4

Where am I going wrong with this module (BMI Calculator)?

BMI Calculator weight=float(input()) height=float(input()) BMI=weight/(height/100)**2 if BMI<18.5: print("Underweight") elif BMI>=18.5 and BMI<25: print("Normal") elif BMI>=25 and BMI<30: print("Overweight") else: print("Obesity")

22nd Nov 2022, 5:20 PM
Mark Leslie Heffernan
11 Réponses
+ 4
Actually, I don't see what's wrong with it... You know that formula uses kg and cm, yes?
22nd Nov 2022, 5:27 PM
Caroline Russell
Caroline Russell - avatar
+ 4
The formula need is BMI = weight / height**2 #not /100
22nd Nov 2022, 6:13 PM
Jayakrishna 🇮🇳
+ 4
Jayakrishna🇮🇳 CODIBILITY That's only true if you're using meters. If he's using centimeters, the divide by 100 is correct.
22nd Nov 2022, 10:43 PM
Caroline Russell
Caroline Russell - avatar
+ 3
weight = int(input()) height = float(input()) BMI = weight /(height ** 2) if BMI < 18.5: print("Underweight") elif BMI < 25: print("Normal") elif BMI < 30: print("Overweight") else: print("Obesity")
22nd Nov 2022, 7:55 PM
Toymak3r
+ 2
Caroline Russell yes. But this code is about python BMI code coach. And description stated the details clearly with formula to be used.. "BMI Calculator: Tracking your BMI is a useful way of checking if you’re maintaining a healthy weight. It’s calculated using a person's weight and height, using this formula: weight / height² 👈 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 Let’s make finding out your BMI quicker and easier, by creating a program that takes a person's weight and height as input and outputs the corresponding BMI category. Sample Input 85 1.9 Sample Output Normal " So that's about my reply..
23rd Nov 2022, 9:08 AM
Jayakrishna 🇮🇳
+ 1
Dianah Delisile There is no && operator in python.
22nd Nov 2022, 5:37 PM
Caroline Russell
Caroline Russell - avatar
+ 1
Jayakrishna🇮🇳 Ah, I didn't know what module OP was referring to. Thanks.
23rd Nov 2022, 6:47 PM
Caroline Russell
Caroline Russell - avatar
0
Mark Leslie Heffernan I don't see anything wrong either. What is the expected behaviour and what happens instead?
23rd Nov 2022, 2:29 AM
Emerson Prado
Emerson Prado - avatar
- 1
I dont speak good english, but in ur code change the command "and" for "or" and enjoy
23rd Nov 2022, 8:37 PM
Rodrigo Quevedo
Rodrigo Quevedo - avatar
- 2
"and", its suppose to be && conditional operator
22nd Nov 2022, 5:35 PM
Dianah Delisile
Dianah Delisile - avatar
- 2
Try, elif 18.5 <= BMI < 25: elif 25 <= BMI < 30 , otherwise it's your conditional if operator nesting
22nd Nov 2022, 5:54 PM
Dianah Delisile
Dianah Delisile - avatar