Problem | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

Problem

I don't understand what Is the problem with this challenge. I should do a bmi calculator. weight=int(input()) height=float(input()) x=0 while x<4: z=weight/height**2 print(z) if z<18.5: print('Underweight') elif z>=18.5 or z<25: print('Normal') elif z>=25 or z<30: print('Overweight') else: print('Obesity')

4th Apr 2023, 7:31 PM
Glo
16 Respostas
+ 10
D Shah šŸŽÆā³ļø Pls avoid giving finished code as answer, because it makes the OP skip the most important part of learning. Prefer giving hints for the OP to find the solution instead.
5th Apr 2023, 12:44 AM
Emerson Prado
Emerson Prado - avatar
+ 7
When you take user inputs you don't assign value to it. Like in your code, you are taking user input for both height & weight. So, assigning value to x will not help in solving problem. Also there is no need of "while" here. Go through the problem description again. Try to understand properly. Hope this helps.
4th Apr 2023, 8:03 PM
D Shah šŸŽÆā³ļø
D Shah šŸŽÆā³ļø - avatar
+ 5
Thanks Emerson Prado for the reminder! Will keep in mind. Have edited my answer.
6th Apr 2023, 9:13 PM
D Shah šŸŽÆā³ļø
D Shah šŸŽÆā³ļø - avatar
+ 4
Happy coding! šŸ–ļøšŸ˜Ž
4th Apr 2023, 8:38 PM
Solo
Solo - avatar
+ 4
weight = int(input("Enter weight in kg: ")) height = float(input("Enter height in meters: ")) x = 0 while x < 4: z = weight / height ** 2 print(z) if z < 18.5: print('Underweight') elif z >= 18.5 and z < 25: print('Normal') elif z >= 25 and z < 30: print('Overweight') else: print('Obesity') x += 1
5th Apr 2023, 12:05 AM
Ė¹į“…į“‡į“ į“‡ŹŸį“į“˜į“‡Ź€ į“›į“§É“į“Šį“‡į“…Ė¼
Ė¹į“…į“‡į“ į“‡ŹŸį“į“˜į“‡Ź€ į“›į“§É“į“Šį“‡į“…Ė¼ - avatar
+ 2
Why are you using a loop? šŸ¤”
4th Apr 2023, 8:01 PM
Solo
Solo - avatar
+ 2
The loop never ends..
5th Apr 2023, 12:49 PM
Gerald Calotes
Gerald Calotes - avatar
+ 2
My suggestion is don't use the loop for this problem and if u are using it so give the counter for x so loop will stop working when x is equal to 4.
6th Apr 2023, 9:39 AM
DIVYANSH VIDHANI
DIVYANSH VIDHANI - avatar
+ 2
Asim Farheen.{-<-{R #, P #, R #, P# & KP#}->-} Pls see my answer to D Shah šŸŽÆā³ļø That said, the code has several issues. Pls review this thread and, if you'd like, do the Python courses.
7th Apr 2023, 1:55 AM
Emerson Prado
Emerson Prado - avatar
+ 1
i used a loop because that was the exercise on that too but also because i thought it was the best solution. I probably complicated my life and I thank you. Now I try Solo D Shah šŸŽÆā³ļø
4th Apr 2023, 8:09 PM
Glo
+ 1
If you checked the result of your code, you would see four answers instead of one... šŸ˜Ž
4th Apr 2023, 8:13 PM
Solo
Solo - avatar
+ 1
No, I think you're just in too much of a hurry... šŸ˜Ž
4th Apr 2023, 8:23 PM
Solo
Solo - avatar
+ 1
I know to learn well I shouldn't have any. I will try to have more patience
4th Apr 2023, 8:24 PM
Glo
+ 1
I tried to put x==4 so it would stop but still it wasn't the right reasoning for that challenge. I do however agree with you that it could be done that way so the loop is not infinite DIVYANSH VIDHANI
6th Apr 2023, 12:36 PM
Glo
0
It's true. I try. I'm stupid sometimes
4th Apr 2023, 8:15 PM
Glo
0
x=0: wgt=int input(input()) hgt=float(input()) bmi=wgt/(hgt**2) if bmi<=16.5: Printf ("Underweight") elif bmi<=27: Printf ("Normal") elif bmi <= 38 Printf ("Overweight") else: Printf ("Obesity") x+=1;
6th Apr 2023, 4:39 PM
ASIM FARHEEN ā„ļøāš”āš”šŸ¤³āš”āš”ā„ļø
ASIM FARHEEN ā„ļøāš”āš”šŸ¤³āš”āš”ā„ļø - avatar