BMI calculator

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • samic
    New Member
    • Jan 2010
    • 3

    BMI calculator

    Hello
    I have just started learning Python and I have so many problem in solving my exercise. I know the answer I have written is not correct. Can any body help me?
    the question is:
    The body mass index (BMI) is calculated as a person’s weight (in pounds) times 720, divided by the square of the person’s height (in inches). A BMI in the range 19-25, inclusive, is considered healthy. Write a program that calculates a person’s BMI and prints a range telling whether they are above, within, or below the healthy range. (20 pts)

    I have written:
    Code:
    def bmi_calculate():
        
        weight, height = input("Enter weight and height seperated by a comma:")
        bmi_calculate = [(weight * 720) / (height * height)]
    
        for bmi_calculate in range (19,25):
            where = 'healthy'
            if bmi_calculate < 19:
                where = 'below'
            elif bmi_calculate > 25:
                where = 'high'
        
    
    print "your bodey mask index is:" , bmi_calculate
    Last edited by bvdet; Jan 2 '10, 07:42 PM. Reason: Add code tags
  • samic
    New Member
    • Jan 2010
    • 3

    #2
    BMI calculator

    I cant run this.
    can any one edit it for me?? Thanks

    Code:
    def bmi_calculate(a,b): #a = weight and b = height
        
        a, b = input("Enter weight and height seperated by a comma:")
        bmi = (a * 720) / (b * b)
        print "the BMI is:" , bmi
    
        for n in range (19,25):
            return 'healthy'
            if n < 19:
                return 'below'
            elif n > 25:
                return 'high'
    print bmi_calculater(a,b)
    Last edited by bvdet; Jan 2 '10, 07:42 PM. Reason: Add code tags

    Comment

    • bvdet
      Recognized Expert Specialist
      • Oct 2006
      • 2851

      #3
      Please don't double post.

      Please use code tags when posting code.

      Refer to our posting guidelines for more information.

      BV - Moderator

      Comment

      • bvdet
        Recognized Expert Specialist
        • Oct 2006
        • 2851

        #4
        Originally posted by samic
        Hello
        I have just started learning Python and I have so many problem in solving my exercise. I know the answer I have written is not correct. Can any body help me?
        the question is:
        The body mass index (BMI) is calculated as a person’s weight (in pounds) times 720, divided by the square of the person’s height (in inches). A BMI in the range 19-25, inclusive, is considered healthy. Write a program that calculates a person’s BMI and prints a range telling whether they are above, within, or below the healthy range. (20 pts)

        I have written:
        Code:
        def bmi_calculate():
            
            weight, height = input("Enter weight and height seperated by a comma:")
            bmi_calculate = [(weight * 720) / (height * height)]
        
            for bmi_calculate in range (19,25):
                where = 'healthy'
                if bmi_calculate < 19:
                    where = 'below'
                elif bmi_calculate > 25:
                    where = 'high'
            
        
        print "your bodey mask index is:" , bmi_calculate
        Do not use bmi_calculate as an identifier, because that is the name of the function.

        Do not enclose the calculation in brackets. That creates a list. Do this instead:
        Code:
        bmi = (weight * 720.0) / height**2
        Why are you using a for loop? You need to determine where the calculation result is with respect to the range 19 through 25. An if/elif block would be appropriate. The first line would be:
        Code:
        if 19 <= bmi <= 25:
        You must return a value. Use the return statement to return bmi.

        You must call the function by following the function name with parentheses. Look at the difference:
        Code:
        >>> print "your bodey mask index is:" , bmi_calculate
        your bodey mask index is: <function bmi_calculate at 0x00C2E1F0>
        >>> print "your bodey mask index is:" , bmi_calculate()
        your bodey mask index is: healthy
        You misspelled body mass!

        Comment

        • samic
          New Member
          • Jan 2010
          • 3

          #5
          Thank you very much for your help

          Comment

          Working...