Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- from sys import argv, exit
- def getinput(question,t):
- inp = None
- while True:
- try:
- inp = t(input(question))
- return inp
- except KeyboardInterrupt:
- exit()
- except:
- print("please input the correct type")
- def lbtokg(lb):
- return lb / 2.202
- def inchtocm(inches):
- return inches * 2.540
- def harris_male(weight,height,age):
- return 66+ 13.7*weight + 5*height - 6.8*age
- def harris_female(weight,height,age):
- return 655 + 9.6*weight + 1.8*height - 4.7*age
- def mifflin_male(weight,height,age):
- return 9.99*weight + 6.25*height - 4.92*age + 5
- def mifflin_female(weight,height,age):
- return 9.99*weight + 6.25*height - 4.92*age - 161
- def katch(LBM):
- return 370 + 21.6*LBM
- def cunningham(LBM):
- return 500 + 22*LBM
- def main(metric=None,sex=None,weight=None,height=None,age=None,bf=None):
- if metric == None:
- metric = getinput("Metric units? y for yes, n for no ",str)
- if metric[0] == 'n' or metric[0] == 'N':
- metric = 0
- else: metric = 1
- if sex == None:
- while sex not in ['m','M','f','F']:
- sex = getinput("Are you a male or female? (m or f) ", str)
- if weight == None:
- weight = getinput("What is your weight? ",float)
- if height == None:
- height = getinput("What is your height? ",float)
- if age == None:
- age = getinput("What is your age? ",float)
- if metric == 0:
- weight = lbtokg(weight)
- height = inchtocm(height)
- if bf==None:
- while True:
- bf = input("Optional: What is your body fat? ")
- if bf == '':
- LBM=None
- break
- else:
- try:
- LBM = weight * (1-(float(bf)/100))
- break
- except:
- print("please input it in correctly")
- elif bf == 0.0:
- LBM = None
- else:
- LBM = weight * (1-(bf/100))
- if sex[0] == 'm' or sex[0] == 'M':
- print("Harris-Benedict: ",harris_male(weight,height,age))
- print("Mifflin-St Jeor: ",mifflin_male(weight,height,age))
- elif sex[0] == 'f' or sex[0] == 'F':
- print("Harris-Benedict: ",harris_female(weight,height,age))
- print("Mifflin-St Jeor: ",mifflin_female(weight,height,age))
- if LBM:
- print("Katch-McArdle: ",katch(LBM))
- print("Cunningham: ",cunningham(LBM))
- if __name__ == '__main__':
- if len(argv) != 1 and (argv[1] == '-h' or argv[1] == '--help'):
- print(\
- """
- -w --weight Set the weight
- -h --height Set the height
- -a --age set the age
- -s --sex set the sex
- -m --metric Use metric values
- -i --imperial Use Imperial/USA values
- -b --bodyfat Used for the optional Katch-McArdle/Cunningham research methods
- --male set the sex to male
- --female set the sex to female
- """)
- exit()
- weight = None
- height = None
- age = None
- sex = None
- metric = None
- bf = None
- index = 1
- while index < len(argv):
- if argv[index] == '-w':
- weight = float(argv[index+1])
- index += 1
- elif argv[index] == '--weight':
- weight = float(argv[index+1])
- index += 1
- elif argv[index] == '-h':
- height = float(argv[index+1])
- index += 1
- elif argv[index] == '--height':
- height = float(argv[index+1])
- index += 1
- elif argv[index] == '-a':
- age = float(argv[index+1])
- index += 1
- elif argv[index] == '--age':
- age = float(argv[index+1])
- index += 1
- elif argv[index] == '-s':
- sex = str(argv[index+1])
- index += 1
- elif argv[index] == '--sex':
- sex = float(argv[index+1])
- index += 1
- elif argv[index] == '--male':
- sex = 'M'
- elif argv[index] == '--female':
- sex = 'F'
- elif argv[index] == '-m':
- metric = 1
- elif argv[index] == '--metric':
- metric = 1
- elif argv[index] == '-i':
- metric = 0
- elif argv[index] == '--imperial':
- metric = 0
- elif argv[index] == '-b':
- bf = float(argv[index+1])
- index += 1
- elif argv[index] == '--bodyfat':
- bf = float(argv[index+1])
- index += 1
- index+= 1
- main(metric,sex,weight,height,age,bf)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement