Python Forum

Full Version: calculate_bai -- TypeError: unsupported operand type(s) for *: 'float' and 'NoneType'
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I'm new to Python, I started learning just over one week ago.

I created my own code to measure my Body Adiposity Index and I keep receiving traceback errors in Python 3.8. I'm sure that the error is a combination of my math import formula as well as nesting functions within functions. I'm not sure how to fix it and I don't understand the console report.

If you can assist that will be appreciated.
Thank you.

Here is the script:
import math
def square_baiheight(x):
    #calculate the square root of height in meters
    n = (int)(math.sqrt(x))
    print(n)
square_baiheight(1.63)

def calculate_bai(x,y):
    #calculate BAI (Body Adiposity Index / Percentage of body fat)
    # x = hip circumference in meters, y = height in meters
    a = 100*x
    b = square_baiheight(1.63)
    c = y*b
    d = c-18
    answer = a/c
    print(answer)
calculate_bai(0.92,1.63)

# Console result is an error
Here is the console error received:
Error:
calculate_bai(0.92,1.63) c = y*b TypeError: unsupported operand type(s) for *: 'float' and 'NoneType' Process finished with exit code 1
Here is the actual BAI calculation:
https://en.wikipedia.org/wiki/Body_adiposity_index

((100x hip circumference in meters)/ (height in meters x the square root of height)) -18
Return is missing in square_baiheight()

import math
def square_baiheight(x):
#calculate the square root of height in meters
 n = (int)(math.sqrt(x))
 print(n)
 return n
square_baiheight(1.63)

def calculate_bai(x,y):
#calculate BAI (Body Adiposity Index / Percentage of body fat)
# x = hip circumference in meters, y = height in meters
 a = 100*x
 b = square_baiheight(1.63)
 c = y*b
 d = c-18
 answer = a/c
 print(answer)
calculate_bai(0.92,1.63)