What's wrong int this code? (python) | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

What's wrong int this code? (python)

weight = int(input("Your weight: ")) height = int(input("Your height: ")) total_height = height * height BMI = weigth / total_height if BMI < 18.5: print("Underweight") elif BMI >= 18.5 and < 25: #what's wrong in this line? print("Normal") elif BMI >= 25 and < 30: print("Overweight") elif BMI > 30: print("Obesity")

19th Oct 2021, 7:23 AM
Zeref Dragneel
Zeref Dragneel - avatar
3 Antworten
+ 2
You should write: Elif BMI >= 18.5 and BMI < 25: and the same at next line
19th Oct 2021, 7:29 AM
Mousa Aboubaker
Mousa Aboubaker - avatar
+ 2
Here are some (correct) ways you can write that line: elif BMI >= 18.5 and BMI<25: elif 25>BMI>=18.5: elif 18.5<=BMI<25: elif BMI<25: The last one should be preferred over the others as the first condition (18.5 <= BMI) is already satisfied by the else part in elif
19th Oct 2021, 8:32 AM
Angelo
Angelo - avatar
+ 1
Zeref Dragneel You have already received some good answers, but there are 2 other problems. 1. Line 4 -> weight is spelt incorrectly which means the variable will not be called. 2. What happens if the BMI ==30? Your code does not cover this. You are close to resolving this. keep going, good luck
19th Oct 2021, 8:59 AM
Rik Wittkopp
Rik Wittkopp - avatar