0

Can you fix my BMI calculation?

Hello there! I am very new to python and I have to do a BMI calculator but unfortunately there is something wrong with my code, it doesn't work. Can you please help me fix it? weight:float(input(85.0/1.9)) if weight >=25: print("Normal") if weight < 18.5: print("Underweight") if weight > 25 or 30: print("Overweight") if weight > 30: print("Obesity") break

14th Mar 2021, 12:58 PM
Programmer269
Programmer269 - avatar
14 ответов
+ 7
First of all I will explain you the working of bmi calculator, in this you have to input both height and weight and then formula of bmi is :- weight/(height*height). Now in your program you should enter height. In line 1:- in python we use '=' in place of ':' and you should use elif and else also in your program and there is unnecessary indentation in your code remove that also. Here's my code, Hope you'll understand!! height = float(input('height in meters:')) weight = int(input('weight in kg:')) bmi = weight/(height*height) 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('obese') else: print('daya kuch to gadbad hai, XD') print('Something is wrong')
14th Mar 2021, 1:18 PM
Vinayak Pandey
Vinayak Pandey - avatar
+ 4
Programmer269 I recommend you to repeat the tutorial and to study every little step carefully on the SL Playground.
14th Mar 2021, 2:09 PM
JaScript
JaScript - avatar
+ 3
There are quite many things you have to learn. The errors are fixed on your original code: weight=float(input(85.0/1.9)) if weight >=25: print("Normal") if weight < 18.5: print("Underweight") if weight > 25 or 30: print("Overweight") if weight > 30: print("Obesity") #break
14th Mar 2021, 1:12 PM
JaScript
JaScript - avatar
+ 3
Programmer269 now also your code doesn't seems good, read my full comment hope you'll understand!!
14th Mar 2021, 1:25 PM
Vinayak Pandey
Vinayak Pandey - avatar
+ 2
var = ... # to do assignement you should take weight and height as input (weight int, height float) and not hardcode them; weigth = int(input()) height = float(input()) then you must compute bmi using inputs: bmi = weight/height**2 and finally do if...elif...else with correction conditions, correct order, an correct indentation: if bmi < 18.5: print('Underweight') elif bmi < 25: print('Normal') elif bmi < 30: print('Overweight') else: print('Obesity') 'break' has nothing to do outside of a loop ^^
14th Mar 2021, 1:30 PM
visph
visph - avatar
+ 1
Oh, now I understand, I changed my code before you wrote this comment weight=float(input(20)) if weight <=18.5 and 25: print("Normal") if weight > 18.5: print("Underweight") if weight < 25 and 30: print("Overweight") if weight < 30: print("Obesity") #break And I didn't know what was going on, now I know. Thanks mate!
14th Mar 2021, 1:23 PM
Programmer269
Programmer269 - avatar
+ 1
Pay attention to your indentation of your original post. Indentation changes the logic in Python.
15th Mar 2021, 4:49 AM
Sonic
Sonic - avatar
0
Thank you!
14th Mar 2021, 1:09 PM
Programmer269
Programmer269 - avatar
0
I know, both of my code were false that's why I showed you because I saw that I missed a few things.
14th Mar 2021, 1:28 PM
Programmer269
Programmer269 - avatar
0
This is my code. I wish it will help you #your code goes here w=int(input()) h=float(input()) bmi=w/h**2 if bmi<18.5: print("Underweight") elif bmi<25: print("Normal") elif bmi<30: print("Overweight") else: print("Obesity")
16th Mar 2021, 12:35 PM
ghenadie tofan
ghenadie tofan - avatar
- 1
Programmer269, Here is my code, hope it helps you!! #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")
16th Mar 2021, 12:33 PM
Shobhit :)
Shobhit :) - avatar
- 2
weight = float(input()) height = float(input()) x = weight / ( height**2) if (x < 18.5): print("Underweight") elif (x >= 18.5 and x < 25): print("Normal") elif (x >= 25 and x < 30): print("Overweight") elif (x >= 30): print("Obesity")
15th Mar 2021, 6:34 PM
Drin Kastrati
Drin Kastrati - avatar
- 3
Programmer269 Here is my code May help you: #your code goes here weight = int(input()); height = float(input()); bmi = weight/float(height*height); 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')
16th Mar 2021, 12:40 AM
❤️😍Prerana😍❤️
❤️😍Prerana😍❤️ - avatar
- 5
All the above explanations are wrong .
15th Mar 2021, 7:33 PM
Janet Wairimu