0
Can you write "while loops condition under another while loops condition?
while BMI <18.5: print("under") while (BMI>=18.5) and (BMI<25): print("normal")
15 Answers
+ 5
You can do it but in you code second while loop won't run, it will rise error becouse loop will run forever and it should look like this(I didn't included stopping the loop):
while BMI <18.5:
print("under")
while (BMI>=18.5) and (BMI<25):
print("normal")
But for code I suppose you want to do I would propose using if/elif/else statment like this
if BMI<18.5:
print("under")
elif BMI<25:
print("normal")
else:
print("BMI is more than 25")
+ 3
But it seems like you are trying to use a while loop as a if statement. And you are not updating BMI. This is an infinite loop.
+ 3
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")
else:
print("obesity")
+ 3
Ok I will still try with the if/elif/else statements.i tried at first but didn't work that's why I asked if it would work if I use the while loops
+ 2
Of course you can have a while loop inside a while loop.
+ 2
Yes, you can write while under while loop , but when there if else is available in python then why you are choosing critical condition.
Use if else , nested if.
+ 2
Yes it's possible but will have to include a condition to break the loop , if not it is an Infinity loop which will result to an error
+ 1
Use if elif else
0
anything wrong with the code
0
I just did scroll up to see it now
0
Yes why not. It's possible
0
Personally, I think 👎
while (condition and condition):
#your code
break
is the wrong thing to use for this task.
I also didn't check the task to see that the logic you were trying to use was correct. It may have an >= incorrectly used where a > was required .....
I solved it (as did most others) with 👍
if elif else.
{EDIT: I did check the task, my code passed all tests}
{EDIT2: Check your output for correct spelling capitalisation and punctuation. It must match the expected output exactly}
0
Yes you cN
- 1
Clinton Obeng Your condition is not changing. You will end up with an infinite loop. Just use if statements as suggested by others.