Python Forum
Trying to create a BMI calculator Help!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to create a BMI calculator Help!
#1
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
Reply
#2
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}")
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020