473,394 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

BMI calculator

3
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:
Expand|Select|Wrap|Line Numbers
  1. def bmi_calculate():
  2.  
  3.     weight, height = input("Enter weight and height seperated by a comma:")
  4.     bmi_calculate = [(weight * 720) / (height * height)]
  5.  
  6.     for bmi_calculate in range (19,25):
  7.         where = 'healthy'
  8.         if bmi_calculate < 19:
  9.             where = 'below'
  10.         elif bmi_calculate > 25:
  11.             where = 'high'
  12.  
  13.  
  14. print "your bodey mask index is:" , bmi_calculate
Jan 2 '10 #1
4 14994
samic
3
I cant run this.
can any one edit it for me?? Thanks

Expand|Select|Wrap|Line Numbers
  1. def bmi_calculate(a,b): #a = weight and b = height
  2.  
  3.     a, b = input("Enter weight and height seperated by a comma:")
  4.     bmi = (a * 720) / (b * b)
  5.     print "the BMI is:" , bmi
  6.  
  7.     for n in range (19,25):
  8.         return 'healthy'
  9.         if n < 19:
  10.             return 'below'
  11.         elif n > 25:
  12.             return 'high'
  13. print bmi_calculater(a,b)
Jan 2 '10 #2
bvdet
2,851 Expert Mod 2GB
Please don't double post.

Please use code tags when posting code.

Refer to our posting guidelines for more information.

BV - Moderator
Jan 2 '10 #3
bvdet
2,851 Expert Mod 2GB
@samic
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:
Expand|Select|Wrap|Line Numbers
  1. 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:
Expand|Select|Wrap|Line Numbers
  1. 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:
Expand|Select|Wrap|Line Numbers
  1. >>> print "your bodey mask index is:" , bmi_calculate
  2. your bodey mask index is: <function bmi_calculate at 0x00C2E1F0>
  3. >>> print "your bodey mask index is:" , bmi_calculate()
  4. your bodey mask index is: healthy
You misspelled body mass!
Jan 2 '10 #4
samic
3
Thank you very much for your help
Jan 2 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: mwh | last post by:
Hi. If you remember, I posted Expressons Help. Now I am making a calculator with javascript. I can't get this to work: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"...
6
by: Rafael | last post by:
Hi Everyone, I need some help with my calculator program. I need my program to do 2 arguments and a 3rd, but the 3rd with different operators. Any help would be great. Here is my code.... ...
3
by: Paul | last post by:
I want to make a simple calculator program but dont know where to get started. This is not GUI but a simple terminal program. It would get input like this Enter number: 5 + 10
3
by: Art | last post by:
Hi, In part of my application the user may need to do a simple arithmetic calculation in order to get the value to put in a text box. I was thinking that it would be good if I could display the...
3
by: PieMan2004 | last post by:
Hi, ive been looking for a solid java community to help me when im tearing out my hair :) Basically ive constructed a GUI that has to represent the same look and functions of the typical windows...
24
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to...
19
by: TexasNewbie | last post by:
This was originally just a calculator without a decimal point. After I added the decimal, it now tells me invalid second number. //GUI Calculator Program import javax.swing.*; import...
5
Deathwing
by: Deathwing | last post by:
Hi everyone one I'm playing around with trying to make an expense calculator. I would like it so that the user can keep enter expenses until they have no more expenses. Then I would like for the...
3
by: itsmichelle | last post by:
This is a very primative code of a java swing calculator. I have assigned all the number buttons and the operator buttons and I can add, subtract, multiply, and divide two numbers together. However,...
3
by: mandy335 | last post by:
public class Calculator { private long input = 0; // current input private long result = 0; // last input/result private String lastOperator = ""; // keeps track of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.