+ 1

Continue / break

'''height = float (input()) weight = float (input ()) BMI = weight / height ** 2 if BMI < 18.5: print ("Underweight") continue elif BMI >= 18.5 and BMI < 25: print ("Normal") continue elif BMI >= 25 and BMI < 30: print ("Overweight") continue elif BMI == 30 or BMI > 30: print ("Obesity") continue Error:::(Continue/break are properly in loop) Why??? ''' ကူညီကြပါဦးးးး

29th Sep 2021, 6:17 PM
HET
4 Antworten
+ 2
Not exactly sure what's wrong with your code, but here is how I solved it: weight = float(input()) height = float(input ()) bmi = weight / (height**2) if bmi < 18.5: print("Underweight") elif bmi > 30: print ("Obesity") elif bmi >= 25 and bmi < 30: print ("Overweight") else: print ("Normal")
29th Sep 2021, 6:38 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 3
In python continue and break are used only inside loops to go to the next iteration and break the loop relatively. In your code there is no loop, that's why you get error, try removing continue statements and your code should work: height = float (input()) weight = float (input ()) BMI = weight / height ** 2 if BMI < 18.5: print ("Underweight") elif BMI >= 18.5 and BMI < 25: print ("Normal") elif BMI >= 25 and BMI < 30: print ("Overweight") elif BMI == 30 or BMI > 30: print ("Obesity")
29th Sep 2021, 6:24 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 1
continue and break are statements you can use within loops. Your code doesn't include any loops.
29th Sep 2021, 6:22 PM
Simon Sauter
Simon Sauter - avatar
0
If I try removing continue statement, I get error in test case:
29th Sep 2021, 6:32 PM
HET