BMI calculator | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

BMI calculator

I need help with this pls (solved)

6th Jan 2023, 4:10 PM
Garfield
Garfield - avatar
8 Answers
+ 2
The problem is with the boundaries (numbers that the "answer" will be) One advice would be to use **elif** instead of multiple **if** statements You can check out this code: https://code.sololearn.com/cfyn2MRebToR/?ref=app
6th Jan 2023, 11:09 PM
Lamron
Lamron - avatar
+ 7
Garfield , to see what your issue is, please link your code here.
6th Jan 2023, 4:12 PM
Lothar
Lothar - avatar
+ 7
Jacinto Tejera González , it is better for you to start your own post, otherwise poeple will not get aware of you. please also include your current code in the post.
8th Jan 2023, 3:32 PM
Lothar
Lothar - avatar
+ 2
h=float(input("Enter your height in meters: ")) w=float(input("Enter your Weight in Kg: ")) BMI=w/(h*h) print("BMI Calculated is: ",BMI) if(BMI>0): if(BMI<=16): print("You are very underweight") elif(BMI<=18.5): print("You are underweight") elif(BMI<=25): print("Congrats! You are Healthy") elif(BMI<=30): print("You are overweight") else: print("You are very overweight") else: print("enter valid details") Hope it help you
7th Jan 2023, 1:42 PM
Alok Pandey
Alok Pandey - avatar
0
Lothar So far I got this: weight = float(input) weight/height**2 if x < 18.5: if x => 18.5 and x < 25: if x => 25 and x < 30: if x => 30:
6th Jan 2023, 4:14 PM
Garfield
Garfield - avatar
0
def calculate_bmi(weight, height): # Calculate BMI bmi = weight / (height ** 2) # Return the result return bmi # Test the function print(calculate_bmi(weight=80, height=1.8)) # Output: 24.69 print(calculate_bmi(weight=70, height=1.7)) # Output: 24.22 print(calculate_bmi(weight=65, height=1.6)) # Output: 25.39 This function takes two arguments: weight and height, which represent the weight and height of the person, respectively. The function calculates the BMI using the formula BMI = weight / (height^2), and it returns the result. I hope this helps! Let me know if you have any questions.
6th Jan 2023, 6:48 PM
Aditya Dixit
0
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") else: print("Obesity")
7th Jan 2023, 7:40 AM
Herobrine
Herobrine - avatar
0
Python if and else explain
7th Jan 2023, 3:57 PM
Ajay
Ajay - avatar