+ 1
Can you guys pls help, I put weight as 130 and height as 1.7 and the output is meant to be obesity but it displays normal
weight=int(input()) height=float(input()) cal= (weight /height**2) if cal <18.5: print("Underweight") else: if cal >= 18.5: print("Normal") else: if cal >=25 <30: print("Overweight") else: if cal >30: print("Obesity")
10 odpowiedzi
+ 4
cal >=25<30 is wrong.
maybe you mean
25<=cal<30
and yes, use elif instead of nested if else.
+ 2
Please search the forum using 'BMI' search term to see how others are solving this task 👍
+ 2
It will always show Underweight or normal. Whatever BMI equal or above 18.5 makes the second if condition true.
Hint 1: if your tests go from lower to higher BMI, you just have to test if BMI < next limit. The BMI >= last limit was already tested in previous if.
Hint 2: instead of nesting if/else blocks, use elif <next condition>. Will look way cleaner.
+ 2
I figured It out, thank you
+ 2
Solo , pls avoid answering with the finished code. The main goal of the app is to help people learn. So giving hints and let people understand and find the solution works best.
BTW, also see the 2 hints in my earlier answer.
+ 2
Emerson Prado, given the fact that Bob_Li has already fixed one condition without paying attention to the previous one, I decided to summarize with this piece of code, especially since I didn’t really like your explanation. Sometimes it’s better to see once than to explain long and tediously, and in my opinion this is just the case, since Zanele has already mastered the logic of this decision in principle.
And since Zanele did not pay attention to my answer, then I can delete it. Happy coding. 😉
+ 2
Here's the problem:
Second if, overrides third and fourth if!
If a>1:
Print ("a")
Elif a>2:
Print ("b")
"b" never happens.
So:
If cal <18.5:
print ("Underweight")
elif cal <= 25:
print ("Normal")
elif cal <= 30:
print ("Overweight")
else:
print ("Obesity")
+ 1
Zanele, press on "@"
0
I'm new to this, I have no idea how to answer ppl
- 1
Oloolo