I have solved a solution for this question, but it is satisfying only two cases, please can anyone help me out.. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I have solved a solution for this question, but it is satisfying only two cases, please can anyone help me out..

Tracking your BMI is a useful way of checking if you’re maintaining a healthy weight. It’s calculated using a person's weight and height, using this formula: weight / height² The resulting number indicates one of the following categories: Underweight = less than 18.5 Normal = more or equal to 18.5 and less than 25 Overweight = more or equal to 25 and less than 30 Obesity = 30 or more Let’s make finding out your BMI quicker and easier, by creating a program that takes a person's weight and height as input and outputs the corresponding BMI category. Sample Input 85 1.9 Sample Output Normal #My attempted code weight = float(input()) height = float(input()) result = weight/height**2 if result<18.5: print("Underweight") if result>=18.5 and result<25: print("Normal") if result>=25 and result<30: print("Overweight") if result>=30: print("Obesity")

25th Jun 2021, 8:26 AM
Falguni Raja
Falguni Raja - avatar
6 Answers
+ 10
weight = float(input()) height = float(input()) result = weight/height**2 if result<18.5: print("Underweight") if result>=18.5 and result<25: print("Normal") if result>=25 and result<30: print("Overweight") if result>=30: print("Obesity")
25th Jun 2021, 8:58 AM
Simba
Simba - avatar
+ 6
Falguni , besides the mentioned issues there is also a small improvement you could do. currently you are using individual if... branches for each case to check. this means that all branches has to be checked, even if the applicable condition is met and the related code already has been executed. instead of this you can use : if...: ... elif ...: ... doing so, the conditional code block will be left when the applicable branch was executed. happy coding!
25th Jun 2021, 9:47 AM
Lothar
Lothar - avatar
+ 2
Yes ,its here now
25th Jun 2021, 8:33 AM
Falguni Raja
Falguni Raja - avatar
+ 2
Simba Thankyou so much
25th Jun 2021, 11:20 AM
Falguni Raja
Falguni Raja - avatar
+ 1
Learn the use of indentation in python and you can find the problem by yourself.
25th Jun 2021, 9:08 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 1
Lothar Thankyou
25th Jun 2021, 11:20 AM
Falguni Raja
Falguni Raja - avatar