Help in BMI CALCULATOR | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8

Help in BMI CALCULATOR

My code weight = w height = h w = int(input()) h = int(input()) r = (w / h**2) if(r <18.5): print:('Underweight') else : if(r >=18.5): if(r < 25): print:('Normal') else : if(r >=25): if(r <30): print:('Overweight') else : if(r >30): print:('Obesity')

11th Dec 2021, 9:44 PM
Adnan Ben Khemis
29 Answers
+ 2
Your code... weight = w height = h #above makes no sense as w and h are not created yet w = int(input()) h = int(input()) #change both int to float r = (w / h**2) #brackets only needed around h**2 so its calculated first if(r <18.5): #brackets not needed after if statement print:('Underweight') else : #this line does nothing if(r >=18.5): if(r < 25): print:('Normal') #colon only needed at end of if condition line not after print see below how you can use elif... else is a last condition if no conditions are met but not needed for this as any number will output a result from print anyway #Code below working after editing your code #weight = w #height = h w = float (input()) h = float (input()) r = w / (h**2) if r <18.5: print('Underweight') elif r >=18.5 and r < 25: print('Normal') elif r >=25 and r <30: print('Overweight') elif r >30: print('Obesity')
13th Dec 2021, 8:00 PM
Chris Biddamaa
Chris Biddamaa - avatar
+ 6
weight = int(input()); height = float(input()); BMI = weight/height ** 2 if BMI < 18.5: print("Underweight") elif 18.5 <= BMI <25: print("Normal") elif 25 <= BMI < 30: print("Overweight") elif BMI >= 30: print("Obesity") Try this method
13th Dec 2021, 2:34 AM
Darren 💯
Darren 💯 - avatar
+ 5
I didnt get r in mine i just done the simplest way the question asked i guess idk if that code works u can just try it my code is weight = float(input()) height = float(input()) if weight / height**2 < 18.5: print("Underweight") elif weight / height**2 < 25: print("Normal") elif weight / height**2 < 30: print("Overweight") elif weight / height**2 >= 30: print("Obesity")
12th Dec 2021, 11:11 PM
Rxkas .0000
Rxkas .0000 - avatar
+ 3
w = int(input('tape your weigth: ')) h = int(input('tape your height: ')) r = (w/((h**2)/10000)) if r < 18.5: print('Underweight') else: if r >=18.5: if r < 25: print('Normal') else: if r >= 25: if r < 30: print('Overweigth') else: if r > 30: print('Obesity')
11th Dec 2021, 11:49 PM
Cleiton Trader
+ 3
def lol(): w = int(input("weight: ")) h = int(input("height: ")) r = ((w/h)**2) if r > 30: return "obesity" if r > 25: return "overweight" if r > 18.5: return "normal" if r < 18.5: return "underweight" print(lol()) This is the easiest way as I know...
12th Dec 2021, 7:41 PM
ing
+ 2
Cleiton Trader i need your help your code didn't work
12th Dec 2021, 5:14 PM
Adnan Ben Khemis
+ 1
w = int(input('tape your weigth: ')) h = int(input('tape your height: ')) r = (w/((h**2)/10000)) if r < 18.5: print('Underweight') else: if r >=18.5: if r < 25: print('Normal') else: if r >= 25: if r < 30: print('Overweigth') else: if r > 30: print('Obesity')
12th Dec 2021, 6:26 PM
Adnan Ben Khemis
+ 1
Dont turn the heights input into a integer make it a float and then its ez
12th Dec 2021, 10:36 PM
Rxkas .0000
Rxkas .0000 - avatar
+ 1
What about this code Rxkas .0000 mariana carneiro mendes w = int(input('tape your weigth: ')) h = int(input('tape your height: ')) r = (w/((h**2)/10000)) if r < 18.5: print('Underweight') else: if r >=18.5: if r < 25: print('Normal') else: if r >= 25: if r < 30: print('Overweigth') else: if r > 30: print('Obesity')
12th Dec 2021, 11:08 PM
Adnan Ben Khemis
+ 1
This might be easier to understand: weight=float(input()) height=float(input()) if((weight/height**2)<18.5): print("Underweight") elif ((weight/height**2)>=18.5) and((weight/height**2)<25): print ("Normal") elif((weight/height**2)>=25) and ((weight/height**2)<30): print("Overweight") elif((weight/height**2)>=30): print("Obesity")
13th Dec 2021, 9:00 AM
elly paul
elly paul - avatar
+ 1
Read Rxkas .0000 and Senthil Kumaran answers. They point you to the right direction. Besides, think again about the comparisons using "greater than". Given the comparisons right before each one, are they really needed?
13th Dec 2021, 1:36 PM
Emerson Prado
Emerson Prado - avatar
0
Maybe you can use these for inspiration: https://code.sololearn.com/W5xBZ1vwT1g4/# https://code.sololearn.com/clcIdgrl1ffZ/#c Python is not a strong suit of mine, I dont think though that print needs the colon char after it ie print:('Underweight') instead print('Underweight') Also someone python smart needs to jump in I'm not sure about your integer math, in other languages the decimals are truncated.
11th Dec 2021, 10:04 PM
William Owens
William Owens - avatar
0
Eu não consegui compilar o código, ele contem alguns erros inclusive na linha 7 (print:('Underweight')) tem : que nao precisa no print:
11th Dec 2021, 10:24 PM
Cleiton Trader
0
Do you have discord ?
12th Dec 2021, 5:32 PM
Cleiton Trader
0
No
12th Dec 2021, 5:50 PM
Adnan Ben Khemis
0
What is you questions?
12th Dec 2021, 6:01 PM
Cleiton Trader
0
Can you give me the solution of this task
12th Dec 2021, 6:15 PM
Adnan Ben Khemis
0
At pydroid 3 the code ran But at sololearn he didin't work
12th Dec 2021, 6:58 PM
Adnan Ben Khemis
0
What i do to write privite msg
13th Dec 2021, 7:58 PM
Adnan Ben Khemis
0
The results are underweight ?
14th Dec 2021, 2:38 AM
Cleiton Trader