Can you help me with the BMI calculator? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can you help me with the BMI calculator?

Hello everyone, please could you help me to review this code, because I really don't understand where I went wrong. Tracking BMI is a useful way to check whether a healthy weight is being maintained. It is calculated from 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 = 18.5 - 24.9 Overweight = 25 - 29.9 Obesity = 30 or more Let's make figuring out your BMI faster and easier by creating a program that takes a person's weight and height as input and generates the corresponding BMI category. Example input 85 1.9 Example output Normal My Code Is: weight=float(input()) height=float(input()) BMI=float((weight/(height**2)) if BMI<18.5: print("Underweight") elif BMI>=18.5 and BMI<= 24.9: print("Normal") elif When reviewing the code it appears that 4 of the 5 tests are correct, however the number 4 says it throws an error message, but that test Is locked

20th Sep 2021, 11:20 PM
Camila León
5 Answers
+ 1
Where's the rest of your code?
20th Sep 2021, 11:53 PM
Simon Sauter
Simon Sauter - avatar
+ 1
Try this: peso=float(input()) altura=float(input()) IMC=peso/altura**2 if IMC < 18.5: print("Underweight") elif < 25: print("Normal") elif IMC < 30: print("Overweight") else: print("Obesity")
20th Sep 2021, 11:59 PM
Simon Sauter
Simon Sauter - avatar
+ 1
Explanation: 1. You don't have to declare that IMC is float because in python the result of a division is float by default. 2. You don't need the parentheses in the definition of IMC because exponentiation comes before division anyway. 3. You don't need the lower bound conditions because those are already fulfilled because of the clauses that come before. 4. Probably the reason your code was not accepted: you left out values between 24.9 and 25.0 and between 29.9 and 30.0.
21st Sep 2021, 12:05 AM
Simon Sauter
Simon Sauter - avatar
+ 1
Thank you so much, it worked ☺️
21st Sep 2021, 12:11 AM
Camila León
0
peso=float(input()) altura=float(input()) Here's my complete code: IMC=float((peso/(altura**2))) if IMC<18.5: print("Underweight") elif IMC>=18.5 and IMC<= 24.9: print("Normal") elif IMC>=25.0 and IMC<= 29.9: print("Overweight") elif IMC>=30: print("Obesity")
20th Sep 2021, 11:54 PM
Camila León