+ 7
How do you create the BMI calculator?
BMI calculator
23 Réponses
+ 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)
+ 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
+ 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 👍
+ 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.
+ 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
+ 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.
+ 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:
+ 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...')
+ 1
I've made this one a long time ago hope this helps
+ 1
Here is my code
https://code.sololearn.com/cxGW7q5k9894/?ref=app
+ 1
Here’s mine for the metric and English system in Python:
https://code.sololearn.com/cYB9DXRW1e4D/?ref=app
https://code.sololearn.com/c6YMJCl4871z/?ref=app
+ 1
https://www.sololearn.com/coach/1020?ref=app
☞︎︎︎take weight and height as input
☞︎︎︎use if else elif statement
0
It's telling me I have a syntax error on line 6. But I can't see where.
0
Are you looking for examples or inpiration? I'm pretty sure you can find loads of them if you search the Code Playground 👍
0
Where do I find that?
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.
0
Thanks. I'll try Lisa. I'm new to this so not too sure what I'm doing.
0
Thank you! That works ☺️
0
Okay thanks