Python Forum
Trying to create a BMI calculator Help! - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Trying to create a BMI calculator Help! (/thread-5553.html)



Trying to create a BMI calculator Help! - jamshaid1997 - Oct-10-2017

name = ( input ('what is your name? '))
height = float( input ("What is your bodys height in meters?"))
weight = float( input ("what is the weight of your body in kilograms?"))
print( name "body mass index is:  " round(weight / (height * height), 2))
hi i am trying to create a BMI calculator that collects the users name and then collects the users weight and height in order to calculate the users BMI however i am getting a syntax error on the last line:
print( name "body mass index is:  " round(weight / (height * height), 2))
for some reason the last quote is the issue

can someone please help


RE: Trying to create a BMI calculator Help! - buran - Oct-10-2017

i would guess that what you try to do is actually
print(name, "body mass index is:  ", round(weight/(height * height), 2))
however there are better ways. Assuming lines 1-3 stay the same, you can replace line 4 with any of the others
print("{0} body mass index is: {1:.2f}".format(name, weight/(height * height)))
bmi = weight/(height * height)
print("{0} body mass index is: {1:.2f}".format(name, bmi))
and only in python3.6+
bmi = weight/(height * height)
print(f"{name} body mass index is: {bmi:.2f}")