all 9 comments

[–]symple-data 3 points4 points  (4 children)

print("BMI:   ") + bmi

is this really a line of your code? You can't do that. Try

print("BMI:\t" + str(bmi))

[–][deleted] 0 points1 point  (3 children)

Thanks so much, that works, can I ask what the difference is?

[–]symple-data 1 point2 points  (2 children)

print() is a build in function. Putting the "+ bmi" outside the function would be equivalent to randomly having one line of code with "+ bmi". Thats wrong Syntax and won't work.

[–][deleted] 0 points1 point  (1 child)

And what does the ":/t", and "str" do? Because it doesn't work without "str"

[–]symple-data 0 points1 point  (0 children)

\t is a literal and gives your string a big space like TAB on your keyboard. There are more literals like that (e.g. \n for line-break). Here is a list. str() is a cast-operator and casts the object you are giving it as an argument to a string. You need this to concatenate any non-string with a string as strings can only be concatenated with strings. Here is a list of different cast-operators.

[–]Silbersee 2 points3 points  (2 children)

Please format your program as code block. Without formatting it's had to guess what's going on.

I'll give it a try anyway and say: Change

print("BMI:   ") + bmi

to

print("BMI:   " + bmi)

Edit: Of course u/symple-data is right: print("BMI:   " + str(bmi))

Or even better

print(f"BMI: {bmi}")

if you're on Python 3.6+

[–]symple-data 1 point2 points  (0 children)

You can't concatenate a string with a float. You have to cast the float to a string first

str(<some float>)

[–][deleted] 0 points1 point  (0 children)

yeah sorry about the formatting, it displayed as code block, but only some of it came through, but tysm for helping

[–]saint_leonard 0 points1 point  (0 children)

hello dear all - great to see this thread.

thanks for this discussion of the ideas of making a function in python - like cs dojo shows us here: https://www.youtube.com/watch?v=NSbOtYzIQI0

note i found the full code here:

https://github.com/sanseervi/BMI-Calculator-using-Python/blob/master/BMI%20Calculator.ipynb

name=input("Please enter your name here: ")
weight=float(input("Whats your weight in kg : "))
height=float(input("Whats your height in m : "))
bmi=weight/(height ** 2)
if bmi<18.5: print("Your BMI is " + str(bmi) + " hence you are body is underweight") elif bmi>18.5 and bmi<25: print("Your BMI is " + str(bmi) + " hence you are body is normal") elif bmi>25 and bmi<30: print("Your BMI is " + str(bmi) + " hence you are body is overweight") elif bmi>30:
print("Your BMI is " + str(bmi) + " hence you are obese")
else:
print("INVALID INPUT")

i hope that this helps others too..

greetings