Last active
September 16, 2018 05:22
-
-
Save Lvl4Sword/d0b1b760e983fabc95f2 to your computer and use it in GitHub Desktop.
Body Mass Index ( Imperial AND Metric )
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
complete = False | |
print('Ctrl+C / Ctrl+D to quit at anytime') | |
def bmi(): | |
try: | |
measurement_type = input('(I)mperial or (M)etric?: ') | |
if measurement_type.casefold() in ['i', 'imperial', 'american']: | |
height = int(input('Height in inches (whole number): ')) | |
weight = int(input('Weight in pounds (whole number again): ')) | |
bmi = round((weight / height ** 2) * 703.0, 2) | |
elif measurement_type.casefold() in ['m', 'metric']: | |
height = float(input('Height in meters (floating number like 1.0): ')) | |
weight = float(input('Weight in kilograms (floating number again): ')) | |
bmi = round((weight / height ** 2), 2) | |
print('Your BMI is {}'.format(bmi)) | |
complete = True | |
return complete | |
except(NameError, UnboundLocalError, ValueError): | |
print("That doesn't look right, let's restart.") | |
except (EOFError, KeyboardInterrupt): | |
print('\nGoodbye!') | |
sys.exit() | |
while not complete: | |
complete = bmi() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment