+ 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")

10th Jun 2022, 9:50 AM
Tashi Wangchuk
29 Respostas
+ 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
10th Jun 2022, 10:21 AM
Lisa
Lisa - avatar
+ 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..
10th Jun 2022, 10:29 AM
Jayakrishna 🇮🇳
+ 2
Lesson 26 BMI calculator
10th Jun 2022, 10:01 AM
Tashi Wangchuk
+ 2
Please try what we have suggested to you. If you still encounter problems then, link your updated code.
10th Jun 2022, 11:28 AM
Lisa
Lisa - avatar
+ 2
elif x>=30: can be replaced by else statement it equals because it's the last test
10th Jun 2022, 7:35 PM
MBZH31
MBZH31 - avatar
+ 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
10th Jun 2022, 2:29 PM
MBZH31
MBZH31 - avatar
+ 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
10th Jun 2022, 2:34 PM
Lisa
Lisa - avatar
+ 1
Yeah your right if we write foat, its more accurate. I write int and it came right.
12th Jun 2022, 8:41 AM
asma
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
10th Jun 2022, 11:26 AM
Tashi Wangchuk
0
Problem
10th Jun 2022, 11:26 AM
Tashi Wangchuk
0
Hi, Weight before height And cast to int weight weight =int(input()) height =float(input())
10th Jun 2022, 12:25 PM
MBZH31
MBZH31 - avatar
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? )
10th Jun 2022, 2:21 PM
Korkunç el Gato
Korkunç el Gato - avatar
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
10th Jun 2022, 2:48 PM
Korkunç el Gato
Korkunç el Gato - avatar
0
MBZH31 I specifically asked about the order not type conversion because it would have worked with both order of assignments on a Python editor. I just wasn't aware SL needed to have this order to be able to do test runs. Thank you, though
10th Jun 2022, 2:51 PM
Korkunç el Gato
Korkunç el Gato - avatar
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
10th Jun 2022, 4:09 PM
Justice
Justice - avatar
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 :-)
10th Jun 2022, 4:11 PM
Korkunç el Gato
Korkunç el Gato - avatar
0
1. Add weight as an int or float type… 2. You need an else statement at the end with empty print()
10th Jun 2022, 5:35 PM
Raunak Pandey
Raunak Pandey - avatar
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
10th Jun 2022, 5:37 PM
Korkunç el Gato
Korkunç el Gato - avatar
0
You sould write: height = float(inpute()) weight = int(input()) If you do not write "int", it will be a string.
11th Jun 2022, 9:47 AM
asma
0
Weight should also be turned into a float
11th Jun 2022, 8:56 PM
Massinissa Kourdache
Massinissa Kourdache - avatar