Python Forum
calculate_bai -- TypeError: unsupported operand type(s) for *: 'float' and 'NoneType'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
calculate_bai -- TypeError: unsupported operand type(s) for *: 'float' and 'NoneType'
#1
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
Reply
#2
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Bug TypeError: 'NoneType' object is not subscriptable TheLummen 4 679 Nov-27-2023, 11:34 AM
Last Post: TheLummen
  TypeError: 'NoneType' object is not callable akbarza 4 922 Aug-24-2023, 05:14 PM
Last Post: snippsat
  Type Error: Unsupported Operand jhancock 2 1,068 Jul-22-2023, 11:33 PM
Last Post: jhancock
  TypeError: 'float' object is not callable #1 isdito2001 1 1,046 Jan-21-2023, 12:43 AM
Last Post: Yoriz
  Write Null values as 0.0 (float) type in csv mg24 3 1,312 Dec-07-2022, 09:04 PM
Last Post: deanhystad
  TypeError: 'float' object is not callable TimofeyKolpakov 3 1,375 Dec-04-2022, 04:58 PM
Last Post: TimofeyKolpakov
  TypeError: 'NoneType' object is not subscriptable syafiq14 3 5,169 Sep-19-2022, 02:43 PM
Last Post: Larz60+
  TypeError: unsupported operand type(s) for +: 'dict' and 'int' nick12341234 1 9,208 Jul-15-2022, 04:04 AM
Last Post: ndc85430
  TypeError: float() argument must be a string or a number, not 'list' Anldra12 2 4,767 Jul-01-2022, 01:23 PM
Last Post: deanhystad
  TypeError: unsupported opperand type(s) for %: 'int' and 'list' cool_person 7 2,099 May-07-2022, 08:40 AM
Last Post: ibreeden

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020