0

Can anybody assist me understanding how to use a loop

Hi Everyone, I am doing the bmi calculator test and currently my code looks like this: weight = float(input()) height = float(input()) bmi = weight / (height * height) while True: print(bmi) if bmi <18.5: print("Underweight") if bmi >= 18.5: if bmi <25: print("Normal") if bmi >=25: if bmi <30: print("Overwieght") if bmi >=30: print("Obesity") It works, however, as it runs every number from 0 to infinite the file is too large. is the way for me to make it run only the numbers input? Or what would you say needs to be looked at? Thanks in advance

23rd Nov 2021, 3:30 PM
Efil Van Erde
Efil Van Erde - avatar
5 odpowiedzi
+ 4
Let me ask you this, did the task require you to use a loop? I mean is your code expected to read and calculate multiple inputs of <weight> and <height>? I had to ask, cause as I see it, the many who had asked questions around this task, they didn't use loops to read inputs of <weight> and <height>. I strongly suggest you to search the forum and Code Playground for similar threads and codes under similar subject (BMI calculator). Lastly, you might also wanna fix the indentation issues in the code. This code covers indentation and might worth a read for better understanding of it. https://code.sololearn.com/cT5BRIbkia21/?ref=app
23rd Nov 2021, 4:12 PM
Ipang
+ 2
Efil Van Erde Why you need loop here?
23rd Nov 2021, 4:10 PM
A͢J
A͢J - avatar
+ 2
Efil Van Erde If you use loop it doens't means that all test cases input will be read together. Test cases means different inputs and different outputs for different inputs. So what is your actual problem here? Did you complete this task or getting some problem?
23rd Nov 2021, 4:26 PM
A͢J
A͢J - avatar
+ 1
It does not ask for loops but there are two tests and the code does not within the same test and the code does not automatically read the second input from test 2
23rd Nov 2021, 4:19 PM
Efil Van Erde
Efil Van Erde - avatar
0
So the task has 2 test cases 1 runs smoothly while the other is not.
23rd Nov 2021, 5:05 PM
Efil Van Erde
Efil Van Erde - avatar