Last active
May 2, 2020 10:03
-
-
Save jonahaung/e6af241baba9d9fa16026caf474d3800 to your computer and use it in GitHub Desktop.
This file contains 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
""" | |
The following application calculates | |
- BMI, | |
- Ideal Weight and | |
- Amount of extra weight | |
from a person's weight and height. | |
""" | |
# convert meter to inch | |
def to_inches(meter): | |
return round(meter * 39.37) | |
# Ideal Weight Calculation, D. R. Miller Formula (1983) | |
def cal_ideal_weight(meter): | |
inches = to_inches(meter) | |
is_male = input("Gender (M/F) - ") == "M" | |
if is_male: | |
# Male: 56.2 kg + 1.41 kg per inch over 5 feet | |
result = (1.41 * (inches - 60)) + 56.2 | |
else: | |
# Female: 53.1 kg + 1.36 kg per inch over 5 feet | |
result = (1.36 * (inches - 60)) + 53.1 | |
return round(result) | |
# BMI Calculation, BMI = weight(kg) / height^2 (m) | |
def cal_bmi(weight, height): | |
# BMI formula | |
result = weight / height ** 2 | |
return round(result) | |
def display_results(weight, ideal_weight, extra_weight, bmi): | |
print("*** Result ***") | |
print("BMI : " + str(bmi)) | |
print("Body Weight : " + str(weight) + "kg") | |
print("Ideal Weight : " + str(ideal_weight) + "kg") | |
print("Extra Weight : " + str(extra_weight) + "kg") | |
# main function to start the process | |
def main(): | |
# user input (height) | |
height = float(input("Your height in meter - ")) | |
# user input (weight) | |
weight = float(input("Your weight in kg - ")) | |
ideal_weight = cal_ideal_weight(height) | |
extra_weight = weight - ideal_weight # body weight - ideal weight | |
bmi = cal_bmi(weight, height) | |
# calling display function | |
display_results(weight, ideal_weight, extra_weight, bmi) | |
# start the process | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment