Advertisement
blink701

BMI Calculator1.py

Mar 9th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.92 KB | None | 0 0
  1. # TODO List: GUI, Enabling user to type ft and inches whilst in imperial system
  2.  
  3. from datetime import datetime
  4.  
  5. name = raw_input('What is your name?: ')
  6.  
  7. gender = raw_input('What is your gender? Male, Female or Other: ').strip()
  8. while gender.lower() not in ('male', 'female', 'other'):
  9.     print('Error! Try again.')
  10.     gender = raw_input('What is your gender? Male, Female or Other: ').strip()
  11.     if gender.lower() not in ('male', 'female', 'other'): continue
  12.  
  13. format_DOB = raw_input('Enter your DOB in dd/mm/yyyy format: ')
  14. DOB = datetime.strptime(format_DOB, '%d/%m/%Y')
  15.  
  16. measurement = raw_input('Do you wish to use the metric system or imperial system?: ').strip()
  17. while measurement.lower() not in ('metric', 'imperial'):
  18.     print('Error! Type metric or imperial only noob!!! Follow the instructions you pleb!')
  19.     measurement = raw_input('Do you wish to use the metric system or imperial system?: ').strip()
  20.     if measurement.lower() not in ('metric', 'imperial'): continue
  21.  
  22. if measurement.lower() == 'metric':
  23.     height = float(input('Enter your height in meters: '))
  24.     weight = int(input('Enter your weight in kilograms: '))
  25.     bmi = weight / height ** 2
  26.  
  27.     if bmi <= 18.5:
  28.         print('Hi %r, you are %r, your age is %r and your Body Mass Index is %r therefore you are underweight') % (name, gender, (datetime.today() - DOB).days/365, bmi)
  29.  
  30.     elif bmi > 18.5 and bmi < 25:
  31.         print('Hi %r, you are %r, your age is %r and your Body Mass Index is %r therefore you have healthy weight') % (name, gender, (datetime.today() - DOB).days/365, bmi)
  32.  
  33.     elif bmi > 25 and bmi < 30:
  34.         print('Hi %r, you are %r, your age is %r and your Body Mass Index is %r therefore you are overweight') % (name, gender, (datetime.today() - DOB).days/365, bmi)
  35.  
  36.     elif bmi > 30:
  37.         print('Hi %r, you are %r, your is %r and your Body Mass Index is %r therefore you are obese') % (name, gender, (datetime.today() - DOB).days/365, bmi)
  38.  
  39. elif measurement.lower() == 'imperial':
  40.     height = float(input('Enter your height in inches: '))
  41.     weight = int(input('Enter your weight in pounds: '))
  42.     bmi = (weight * 703) / height ** 2
  43.  
  44.     if bmi <= 18.5:
  45.         print('Hi %r, you are %r, your age is %r and your Body Mass Index is %r therefore you are underweight') % (name, gender, (datetime.today() - DOB).days/365, bmi)
  46.  
  47.     elif bmi > 18.5 and bmi < 25:
  48.         print('Hi %r, you are %r, you are %r, your age is %r and your Body Mass Index is %r therefore you have healthy weight') % (name, gender, (datetime.today() - DOB).days/365, bmi)
  49.  
  50.     elif bmi > 25 and bmi < 30:
  51.         print('Hi %r, you are %r, your age is %r and your Body Mass Index is %r therefore you are overweight') % (name, gender, (datetime.today() - DOB).days/365, bmi)
  52.  
  53.     elif bmi > 30:
  54.         print('Hi %r, you are %r, your age is %r and your Body Mass Index is %r therefore you are obese') % (name, gender, (datetime.today() - DOB).days/365, bmi)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement