Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Added BMI calculator #305

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Basic-Scripts/bmi_calc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python3.7

# BMI = (weight in kg / height in meters squared)

def gather_info():
height = float(input("What is your height? (inches or meters) "))
weight = float(input("What is your weight? (pounds or kilograms) "))
system = input("Are your measurements in metric or imperial units? ").lower().strip()
return (height, weight, system)

def calculate_bmi(weight, height, system='metric'):
"""
Return the Body Mass Index (BMI) for the
given weight, height, and measurement system.
"""
if system == 'metric':
bmi = (weight / (height ** 2))
else:
bmi = 703 * (weight / (height ** 2))
return bmi

while True:
height, weight, system = gather_info()
if system.startswith('i'):
bmi = calculate_bmi(weight, system='imperial', height=height)
print(f"Your BMI is {bmi}")
break
elif system.startswith('m'):
bmi = calculate_bmi(weight, height)
print(f"Your BMI is {bmi}")
break
else:
print("Error: Unknown measurement system. Please use imperial or metric.")