+ 3
Can someone please help me with this?
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
19 Answers
+ 4
Hi HungryTrade ,
I see, you are right ๐ Thanks for clearence
+ 4
Thank you so much guys, I've cleared the bugs
+ 3
Essien Bukola Hi,
SoloLearn accepts 2 inputs, there is no doubt. So you don't need to go anywhere else to try your code.
In your if statement, there you didn't add the values in between. For example when a value < 25 it is also < 18,5 right? what will your code execute in such a situation, think it carefully again.
Hope this clue helps, have fun with coding :)
+ 2
This is my code so far 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")
elif(Bmi >=30):
print("Obese"
+ 2
You can try https://jupyter.org/try then click on "Jupyter Notebook", a window will load and then you can create different notebooks and in each notebook you can directly type python and running it without install Python environment.
This is an application that you also can download and use directly on your computer.
You may find some tutorial of How to use, online.
+ 2
Geoffrey L {seems that SoloLearn doesn't accept 2 inputs} that isn't correct, for two inputs in "code bits" you use the enter key between inputs, then press submit.
For "code challenge" the playground will send two values (or more in other challenges) to your code.
Essien Bukola your code is close. Does it pass all the test cases?
EDIT: {You may need to read the instructions again, you are close but your logic is including some values that should be in the next group. Also, check your outputs, one isn't 100% match for the expected output.}
+ 2
Also, I think they expect you to have the full word. So just printing 'Obese' isn't enough.
+ 2
G'day Jackie well done for solving it so neatly. We try to not publically post the answers to SoloLearns learning challenges.
Also, did you see my thing about "tearing off values"? Your code starts with tearing off anything bigger than 30. โ
Remaining values must be <=30. So the next elif will not get to check any values bigger than 30 (so no need to ๐<30 and๐).
It isn't a big problem, but does make your code even more elegant. ๐๐บ
+ 1
What have you try so far?
+ 1
G'day Gunessina the if - elif chain is ok to catch the values in between because it is eliminating the lower values as it progresses to the next.
I mean, ๐if (Bmi <18.5):๐ catches all smaller values, so the next elif won't have any values less than 18.5, ok?
Essien Bukola used some inaccurate logic, it needs ๐elif (Bmi <25):๐ because =25 should be in the next group. The next elif statement is also incorrectly catching =30 when the question says equal to 25 and less than 30....
+ 1
So this is the answer to the question:
BMI=0
weight=float(input()) #weight in Kg
height=float(input()) #height in M
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")
+ 1
The question asks both larger and equal to.
0
Essien Bukola, I think the only "error" is the missing ")" at the end of your code.
It seems that Sololearn doesn't accept 2 inputs.
I just try your code on another website and it works.
0
Oh really?
That's great.
Seems sololearn has some hidden principles.
What website was that?
0
Geoffrey L, yes.. it passes all the test cases except one
0
Essien Bukola congratulations!
Yes, you need to copy the output exactly, spelling, punctuation, and capital letters must match. I copy+paste the instructions into my challenge code, then I cut+paste the words into my output lines.
You definitely don't need the and in your elif statements, because you are checking from smallest to largest. Try this ๐elif BMI <25:๐
Think of the if-elif as tearing off parts of a paper list, the condition chooses where to cut, the previous part is already gone.
0
weight =float(input())
height=float(input())
bmi= weight /(height * height )
if bmi > 30:
print ("Obesity")
elif bmi < 30 and bmi >=25:
print ("Overweight")
elif bmi < 25 and bmi >=18.5:
print ("Normal")
elif bmi < 18.5:
print ("Underweight")
0
Change
if bmi >= 30:
Then its perfect