+ 7

How do you create the BMI calculator?

BMI calculator

14th Sep 2021, 2:03 PM
Emma Cooke
23 Answers
+ 8
This is my current code weight = int(input()) height = float(input()) BMI = (weight / height**2) if BMI < 18.5: print(underweight) elif BMI >= 18.5 and < 25: print(normal) elif BMI >= 25 and < 30: print(overweight) elif BMI >= 30: print(obesity)
14th Sep 2021, 2:04 PM
Emma Cooke
+ 6
Underweight and so on (inside the print statement) need to be strings. And I think the elif should be on the same level as the if
14th Sep 2021, 2:07 PM
Lisa
Lisa - avatar
+ 5
Emma Cooke I did a few changes to your code. https://code.sololearn.com/c2271xpNVVZZ/?ref=app So your mistakes are : 1) indentation 2) did not use quotation marks " " inside print() Hope this helps 👍
14th Sep 2021, 2:31 PM
ŁØVƏŔ
ŁØVƏŔ - avatar
+ 4
Thanks. I've just had a quick look and I don't understand what's in those codes. They're well beyond me. I'm just starting out for a bit of fun. But maybe in the future. I've tried what you suggested Lisa. But it's still coming up with this line 6 syntax error.
14th Sep 2021, 2:17 PM
Emma Cooke
+ 4
I just noticed your code, and from what I see, you need to first understand that correct code indentation in Python is crucial. Wrong code indentation breaks a code. This might help you to better understand what, and how code indentation be done 👇 https://code.sololearn.com/cT5BRIbkia21/?ref=app
14th Sep 2021, 2:28 PM
Ipang
+ 1
Emma Cooke Can you please put your code in a playground script and link it? That way we can test it and see what line 6 actually is.
14th Sep 2021, 2:24 PM
Lisa
Lisa - avatar
+ 1
In the elif, BMI is also required in the part after the "and", like this: elif BMI >= 18.5 and BMI < 25: ... elif BMI >= 25 and BMI < 30:
14th Sep 2021, 2:43 PM
Lisa
Lisa - avatar
+ 1
H = float(input('Enter your height: ')) W = float(input('Enter your weight: ')) print(" ") BMI = W/H**2 B = str(int(BMI)) if BMI <= 18.5: print('your BMI is '+B+' you are Underweight') elif BMI <= 24.9 and BMI > 18.5: print('your BMI is '+B+' you are Normalweight') elif BMI <= 29.9 and BMI > 24.9: print('your BMI is '+B+' you are Overweight') elif BMI <= 34.9 and BMI > 29.9: print('your BMI is '+B+' you are Obesity class I') elif BMI <= 39.9 and BMI > 34.9: print('your BMI is '+B+' you are Obesity class II') else: print('your BMI is '+B+' you are Obesity class III') print(" ") input('Press Enter to Exit...')
15th Sep 2021, 3:58 PM
Bhuvaneshwaran M
Bhuvaneshwaran M - avatar
+ 1
I've made this one a long time ago hope this helps
15th Sep 2021, 3:59 PM
Bhuvaneshwaran M
Bhuvaneshwaran M - avatar
16th Sep 2021, 2:47 AM
Vishal Kumar Singh
Vishal Kumar Singh - avatar
16th Sep 2021, 7:54 AM
Musaab
Musaab - avatar
+ 1
https://www.sololearn.com/coach/1020?ref=app ☞︎︎︎take weight and height as input ☞︎︎︎use if else elif statement
16th Sep 2021, 12:54 PM
Krïśh Ĺövė
0
It's telling me I have a syntax error on line 6. But I can't see where.
14th Sep 2021, 2:04 PM
Emma Cooke
0
Are you looking for examples or inpiration? I'm pretty sure you can find loads of them if you search the Code Playground 👍
14th Sep 2021, 2:05 PM
Ipang
0
Where do I find that?
14th Sep 2021, 2:05 PM
Emma Cooke
0
Are you using SoloLearn app or web? In web, you can see the link in main menu https://www.sololearn.com/Codes/ In app, it's the section you can visit by tapping the bottom nav bar, the one with {} icon.
14th Sep 2021, 2:08 PM
Ipang
0
Thanks. I'll try Lisa. I'm new to this so not too sure what I'm doing.
14th Sep 2021, 2:31 PM
Emma Cooke
14th Sep 2021, 2:41 PM
Emma Cooke
0
Thank you! That works ☺️
14th Sep 2021, 6:25 PM
Emma Cooke
0
Okay thanks
15th Sep 2021, 1:04 PM
Odonghanro Faith
Odonghanro Faith - avatar