New course! Every coder should learn Generative AI!
Try a free lesson+ 6
#The error is in "BMI=" since nothing is happening
#the error is in BMI = (weight/(height**2)): now that #it has ":". in which it is not valid in python
#In this part of your code you need to set ls variable #BMI < 30
elif BMI >=25 and <30:
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:
print("Obesity")
+ 6
Lothar,
Hello colleague, first of all I am helping you solve your problem through the explanation I provide so that you can move forward, seeing and correcting your error.
It is better that you move forward rather than stay stagnant, colleague. From my point of view, I know that there are those who are passionate about programming who will analyze their mistakes and not make it again.
+ 4
STE4LPH ,
may be this gives you a better insight of what i mean with my post.
> a ready-made code can just lead to a copy and paste action. it does not necessarily need to step deeper and requires not much effort and time.
> the answer from Brian can be seen on how we can give hints and support, but gives a chance to the asker to elaborate, practice himself and having an active self-learning experience.
this is what brings us forward.
let me give you an example: i started coding in 1985 with the programming in basic programming language. at this time, there was no internet, social media or whatever, but learning by doing.
+ 3
Amrita Samantara there are two syntax errors, two logic errors, and one task requirements mismatch.
Syntax Errors
Others pointed out the two syntax errors. I'll reiterate them:
File "/usercode/file0.py", line 4
BMI = (weight/(height**2)):
SyntaxError: invalid syntax
[spurious : at the end]
And
File "/usercode/file0.py", line 9
elif BMI >=25 and <30:
SyntaxError: invalid syntax
[missing BMI before <30]
Two Logic Errors
The logic fails if BMI=18.5, also BMI=30.
Too much checking is getting you into trouble. Keep it simple. Consider when BMI<18.5 is False, then it stands to reason that BMI >=18.5 is True. There is no need to actually check BMI>=18.5. (Notice that your code is missing the =, which leaves a hole in its logic). You may just write
elif BMI<25:
Use that simplified logic for the <30 threshold, too.
elif BMI<30:
For 30 and above, use simply
else:
Task Requirements Mismatch
The order of program inputs does not match the order given by the problem description. Get weight first. Done!
+ 2
STE4LPH ,
it is not seen as very helpful to give ready-made codes.
> use tips and hints, so that the asker has a chance to solve the task by himself.
+ 1
Amrita Samantara ,
The parser and compiler already tell you some of that stuff automatically.
You should get in the habit of scrolling to the bottom and reading what the last error message actually says then going to the line number it says and fixing the error. Even if your code has a lot of errors, you can fix one and run the code again to get the next one, repeating until none are left. Then, if the code still doesn't do what you want it to do, it's a design problem that can better be solved with help from your fellow humans.
0
height = float(input('insert height in merer'))
weight = float(input('insert weight in kg'))
BMI = (weight/(height**2))
print(BMI)
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:
print("Obesity")
0
The bug occurs at that point where the variable "BMI" is created and assigned to "(weight/(height**2)):" using the operator "=". The code throws a syntax error, this is because the colon (:) is not necessary for ending the particular line of code in python. It is considered invalid.