Is there a cleaner and more efficient way to make these BMI & Fat% calculators in Python?

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Is there a cleaner and more efficient way to make these BMI & Fat% calculators in Python?



I'm new to python (and coding in general & SOF). I recently picked it up after going through some online HTML, CSS tracks on Treehouse and really enjoy it until now. Apart from the hobby aspect my general bigger goal is to be able to write my own web applications/programs related to my field of work & study (healthcare).



So.. My question is related to this piece of code I wrote today. It's a general BMI calculator and also includes a fatpercentage estimator (based on a few variables that need to be provided). It's by no means a 100% accurate fat% calculator (you'd need a DXA-scan to get a better idea), although it works fine for the general public.



Questions:



1) How do I make sure that a user can input multiple things into the height prompt? Some users might want to add 187 and others will put in 1.87. How do I account for this and make sure the calculator still works?



2) Do I need to write all those print statements in my functions or is there a cleaner/better way to write these functions?



3) If I want the user to be able to select the imperial or metric system? How do I do this and do I need to make 2 extra functions for these?



Thanks in advance and here is the code:


# BMI calculator & fatpercentage estimator

#VARS

gender = input("What is your gender? Male or female? ")
age = input("How old are you? ")
length = float(input("What is your length in meters? Input should be: 1.80 for example. "))
weight = int(input("How much do you weigh (in KG)? "))
userinput_fatpercentage = int(input("What is your fatpercentage?nReturn 0 (zero) if you don't know and want to calculate. "))
bmi = round(weight/(length*length), 2)

# BMI CALC

def bmi_calulation():
if bmi <= 18.5:
print("Your Body Mass Index is:", bmi, "start eating skinny b*tch.")
elif bmi > 18.5 and bmi < 25:
print("Your Body Mass Index (BMI) is: ", bmi, "you are a normal person, thank god.")
elif bmi > 25 and bmi < 30:
print("Your Body Mass Index (BMI) is: ", bmi, "mind you... You are overweight. Drop some weight.")
elif bmi > 30:
print("Your Body Mass Index (BMI) is: ", bmi, "Hnnngggg..! You are insanely fat. Stop eating!")
else:
print("There was an error with your input. Try again.")

# FAT% ESTIMATOR

def fatpercentage_calculation():
if userinput_fatpercentage == 0 and gender.lower() == 'male':
print("Your fatpercentage is: ")
print(round((1.2 * float(bmi) + (0.23 * float(age) - (10.8 * 1) - 5.4)), 2))
elif userinput_fatpercentage == 0 and gender.lower() == 'female':
print("Your fatpercentage is: ")
print(round((1.2 * float(bmi) + (0.23 * float(age) - (10.8 * 0) - 5.4)), 2))
elif userinput_fatpercentage == userinput_fatpercentage:
print("Your fatpercentage is: {}.".format(userinput_fatpercentage))
else:
print("Something went wrong. Try again. ")

#Output

bmi_calulation()
fatpercentage_calculation()









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

BGpDh0m,V3Q,n,ht6tGsBHcbGFd,6hnqYEoBg1Z T,yIAqHIVoo9WKOrEA,Bnzb9DCS8N,XP5ADkSZy9,4K,45Nz PNOuTDwoB8pjT wWgx9pX
FHxvVgiAmv0c a0 yNVuGUUGAxPdGG7BpgbDg4H dy

Popular posts from this blog

Makefile test if variable is not empty

Visual Studio Code: How to configure includePath for better IntelliSense results

Will Oldham