Sie sind auf Seite 1von 1

a_weight = weight in kg

a_height = height in cm

def bmi(a_weight, a_height):


check_parameter(a_weight)
check_parameter(a_height)
bmi_value = float(a_weight) / (float(a_height) / 100)
check_parameter(bmi_value)
return bmi

def check_parameter(a):
if type(a) == str or type(a) == bool:
raise TypeError("ERROR_TYPE")
if int(a) < 0 or float(a) < 0:
raise ValueError("ERROR_NONPOSITIVE")
return a

def bmi_calculator(a_weight, a_height):


while type(a_weight) == str or type(a_weight) == bool or a_weight < 0:
a_weight = None
a_weight = input("Enter a correct weight value in kg: ")
a_weight = float(a_weight)
while type(a_height) == str or type(a_height) == bool or a_height < 0:
a_height = None
a_height = input("Enter a correct height value in cm: ")
a_height = float(a_height)
bmi = a_weight / (a_height / 100)
return round(bmi)

def bmi_calculator(a_weight, a_height):


while type(a_weight) != int or type(a_weight) != float or a_weight < 0:
a_weight = None
a_weight = input("Enter a correct weight value in kg: ")
a_weight = float(a_weight)
while type(a_height) != int or type(a_height) != float or a_height < 0:
a_height = None
a_height = input("Enter a correct height value in cm: ")
a_height = float(a_height)
bmi = a_weight / (a_height / 100)
return round(bmi)

Das könnte Ihnen auch gefallen