Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

10 points) Write an HTML page called bmi.html which will contain a form. The for

ID: 665401 • Letter: 1

Question

10 points) Write an HTML page called bmi.html which will contain a form. The form should have three text fields (use the text type for the input element) and one submit button, labeled “Calculate BMI”. One text field gets the weight of the person (in pounds), one text field gets the feet part of height and another gets the inches part of height.

(20 points) The form’s action URL should be a Python CGI called bmi.cgi. Write this program so that it reads the values from the text fields and then calculates the BMI of a person.

If the values of the text field are numbers, then the CGI should return a page of the form

Your weight is X lbs.
Your height is Y feet Z inches. Your BMI is Result.

where X, Y and Z are the values from the text fields and Result is the result of the calculation.

Formula for calculating BMI:
BMI = (weight(lbs)*703)/( height(in)*height(in) )

Use the conversion: 1 feet = 12 inches

(10 points) In case the user does not provide a number in any one of the text fields, or enters something other than a number, your CGI page should return a web page with an error message.

(10 points) In addition to their BMI, print out which category this puts them in. http://en.wikipedia.org/wiki/Body_mass_index#Categories

CGI PAGE MUST BE IN PYTHON -- please no Java responses.

Explanation / Answer

<!--   BMI.html -->

<!doctype html>
<html>
<head>
<title>BMI Calculator</title>
</head>
<body>
   <form action="/cgi-bin/bmi.cgi" method="post">
       Weight(in pounds): <input type="text" name="weight"><br/>
       Height(feet part): <input type="text" name="heightf"><br/>
       Height(inch part): <input type="text" name="heighti"><br/>
       <input type="submit" value="Calculate BMI" />
   </form>
</body>

# bmi.cgi

#!/usr/bin/python
import cgi, cgitb
form = cgi.FieldStorage()

weight = form.getvalue('weight')
heightf = form.getvalue('heightf')
heighti = form.getvalue('heighti')
height = heightf * 12 + heighti
bmi = (double(weight) * 703) / (height * height)

print 'Content-type:text/html '
print '<html>'
print '<head>'
print '<title>BMI</title>'
print '</head>'
print '<body>'
print 'Your weight is ', (weight), 'ibs <br>'
print 'Your height is ', (heightf), 'feet ', (heighti), 'inches <br>'
print 'Your BMI is ', (bmi)
print '</body>'
print '</html>'

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote