Adding floating numbers in python -
trying add together bmi results , display it, maintain getting error :
typeerror: 'float' object not iterable
also maintain getting none printed when run programme after bmi calculated>?
def bmirange(): if bmi >= 25.0: print('your bmi measurement shows overweight') elif bmi <18.0: print('your bmi measurement shows underweight') else: print('your bmi measurement shows in healty weight band') weight = float(input('what weight in kg? ')) height = float(input('what height in meters? ')) bmi = weight / (height * height) print(bmi) print(bmirange()) bmiredo = input('do want bmi measurement?, y / n ') while bmiredo == 'y': weight = float(input('what weight in kg? ')) height = float(input('what height in meters? ')) print(bmi) print(bmirange()) bmiredo = input('do want anoher bmi measurement?, y / n ') else: print('ok, total of bmi results are') print(sum(bmi)) input('press come in key exit')
the problem here:
print(sum(bmi)) the bmi variable number, if want utilize sum() need list of numbers. here how can collect list of numbers. .append() method adds element end of list.
bmi_list = [] ... bmi = weight / height**2 bmi_list.append(bmi) ... while ...: .... bmi = weight / height**2 bmi_list.append(bmi) ... ... print(sum(bmi_list)) note there error bmirange(): print() called twice. can either set print() within bmirange(), or can print() results of bmirange(), doing both result in none beingness printed out, assume not want.
def bmirange(): if bmi >= 25.0: print('your bmi measurement shows overweight') elif bmi <18.0: print('your bmi measurement shows underweight') else: print('your bmi measurement shows in healty weight band') ... bmirange() # print solution 2 def bmirange(): if bmi >= 25.0: homecoming 'your bmi measurement shows overweight' elif bmi <18.0: homecoming 'your bmi measurement shows underweight' else: homecoming 'your bmi measurement shows in healty weight band' ... print(bmirange()) # not print python python-3.x
No comments:
Post a Comment