+ 4
What is wrong with my code?
height =float(input()) weight =input() x =weight/(height**2) if x<18.5: print("Underweight") elif 18.5<=x<25: print("Normal") elif 25<=x<30: print("Overweight") elif x>=30: print("Obesity")
29 Réponses
+ 12
Read the task description again:
1. input is weight
2. input is height
Both weight and height need to be converted to a numeric data type
+ 5
Pls add task description also..
I think, first input is weight and 2nd input is height.
And as already mentioned both are should be converted to numbers..
+ 2
Lesson 26
BMI calculator
+ 2
Please try what we have suggested to you.
If you still encounter problems then, link your updated code.
+ 2
elif x>=30: can be replaced by else statement
it equals because it's the last test
+ 1
Korkunç the Terrible Frusciante
2 reasons
First
As Lisa wrote:
Read the task description again:
1. input is weight
2. input is height
Both weight and height need to be converted to a numeric data type
Second
As Tashi wrote:
Sample input
85
1.9
I think 85 is weight and not height
+ 1
Korkunç the Terrible Frusciante
Order matters if it is a sololearn task so the code can pass the test cases. The formula will give the wrong metric if you swap inputs
+ 1
Yeah your right if we write foat, its more accurate. I write int and it came right.
0
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
0
Problem
0
Hi,
Weight before height
And cast to int weight
weight =int(input())
height =float(input())
0
MBZH31 What does it matter if she prompts for height input first?
The formula using both variables is underneath them? It's not like the variables are used before assignment? (unless you meant something else, that she divided height by weight squared, before editing it, perhaps? )
0
Lisa 😳 I think I survived SL thus far without knowing that, and it might have dearly taken away some time from me, and I now understand the cause of my perplexion with some of the failures then. Thank you :), it's gonna help with the other languages I'll move onto on SL
0
Korkunç the Terrible Frusciante That's why I admit I misinterpreted. I'm sorry about that. I'm also going to delete my initial response cause I'm just spouting nonsense now LOL
0
Justice You're actually saying that to a fulltime nonsense spouter. It's just a misunderstanding and your code is educational, do not delete that please :-)
0
1. Add weight as an int or float type…
2. You need an else statement at the end with empty print()
0
Raunak Pandey (2) No she doesn't. I mean ifs don't need elses to get executed, but when used as ternary operators, they do, AFAIK
0
You sould write:
height = float(inpute())
weight = int(input())
If you do not write "int", it will be a string.
0
Weight should also be turned into a float