[Python] Indent question when using if (first time coding)

Asked 2 years ago, Updated 2 years ago, 152 views

I'm trying to determine if I'm overweight and underweight by BMI index.

if BMI<18.5:
    print("Your BMI indicates that you are underweight.")
    if BMI>25:
        print("Your BMI indicates that you are overweight.")
else:
    print("Your BMI indicates that you are optimal weight.")

When I wrote it like this, even when my BMI is over 25, it says optimal weight How can I fix it so that it comes out the way I want it to?

python if문

2022-09-22 18:13

1 Answers

Can we satisfy BMI < 18.5 and BMI > 25? No, so if under if will never run in this code.

You'll have to do this.

  of # to nose into a person's weight.Py
if BMI < 18.5:
    Print low (" .. so you do. A little bit fat. ")
else:
    Print, " not underweight.")
    if BMI > 25:
        Print (" but overweight. Lose some weight. ")


2022-09-22 18:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.