Python Forum
TypeError: Not supported between instances of 'function' and 'int'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: Not supported between instances of 'function' and 'int'
#1
Hi all, I am new to programming and am trying (learning) to build a calculator to calculate the risk of heart diseases based on a few variables. Part of the calculation requires recognition of certain high risk criteria and this is where I am at the moment. The code is split into two files, variables.py (the variables module) and framingham.py:

Variables.py:
def age():
  a = eval(input("Please enter age in years: "))
  if a < 35:
    return 35
  else:
    return a

def systolic_blood_pressure():
  b = eval(input("Please enter SBP: "))

  if b < 75:
    return 75

  else:
    return b

def cholesterol_ratio(total_cholesterol, HDL_cholesterol):
    ratio = total_cholesterol/HDL_cholesterol

    return ratio

def smoker():
  a = eval(input("Are you a smoker? 0 = no, 1 = yes " ))
  return a

def diabetes():
  a = eval(input("Are you a diabetic? 0 = no 1 = yes " ))
  return a

def LVH():
  a = eval(input("Does the ECG show LVH? 0 = no 1 = yes " ))
  return a

total_cholesterol = eval(input("Please enter total cholesterol. "))
HDL_cholesterol = eval(input("Please enter HDL cholesterol. "))
framingham.py (incomplete):
import variables
from sys import exit

#define and return if high risk criteria present
class highrisk(object):

  def __init__(self, age, diabetes, systolic_blood_pressure, total_cholesterol):
    self.age = variables.age
    self.diabetes = variables.diabetes
    self.systolic_blood_pressure = variables.systolic_blood_pressure
    self.total_cholesterol = variables.total_cholesterol

    if total_cholesterol >= 7.5:
        print("You are at high risk of developing heart disease. ")

    elif systolic_blood_pressure >= 180:
        print("You are at high risk of developing heart disease. ")

    elif age >= 60 and diabetes == 1:
        print("You are at high risk of developing heart disease. ")

    else:
        pass #no output needed if none of the criteria are met

#actual risk calculator
class risk_calculator_male():
    pass

class risk_calculator_female():
    pass

highrisk(variables.age, variables.diabetes, variables.systolic_blood_pressure, variables.total_cholesterol)
(The pass in the last 2 classes are temporary as I haven't finished researching/planning the formula yet)
When I run framingham.py in the CLI, I get the following traceback:

Error:
PS D:\python\framingham> python framingham.py Please enter total cholesterol. 5 Please enter HDL cholesterol. 1 Traceback (most recent call last): File "framingham.py", line 32, in <module> highrisk(variables.age, variables.diabetes, variables.systolic_blood_pressure, variables.total_cholesterol) File "framingham.py", line 16, in __init__ elif systolic_blood_pressure >= 180: TypeError: '>=' not supported between instances of 'function' and 'int'
I thought the eval() function already converts the string to int/float?

Some help would be much appreciated. Thanks
Reply


Messages In This Thread
TypeError: Not supported between instances of 'function' and 'int' - by palladium - Nov-23-2019, 01:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Using curve_fit to optimize function (TypeError) Laplace12 4 2,525 Aug-30-2021, 11:15 AM
Last Post: Larz60+
  [Solved] TypeError when calling function Laplace12 2 2,904 Jun-16-2021, 02:46 PM
Last Post: Laplace12
  Sort Function: <' not supported between instances of 'float' and 'tuple' quest 2 8,097 Apr-30-2021, 07:37 PM
Last Post: quest
Exclamation TypeError: '>=' not supported between instances of 'int' and 'str' helpme1 11 8,834 Mar-11-2021, 11:13 AM
Last Post: helpme1
  Type error: '>' not supported between instances of 'NoneType' and 'int' spalisetty06 1 10,491 Apr-29-2020, 06:41 AM
Last Post: buran
  TypeError: '<' not supported between instances of 'str' and 'int' Svensation 5 8,851 Jan-20-2020, 08:12 PM
Last Post: buran
  TypeError: '>=' not supported between instances of 'str' and 'int' AsadZ 8 10,542 Aug-20-2019, 11:45 AM
Last Post: ThomasL
  '>' not supported between instances of 'str' and 'int' graham23s 2 3,999 May-11-2019, 07:09 PM
Last Post: micseydel
  Newbie Question re "TypeError: '<' not supported between instances of 'list' and 'int sr12 8 13,115 Apr-11-2019, 08:19 PM
Last Post: sr12
  '<' not supported between instances of 'str' and 'int' jayaherkar 1 7,954 Apr-09-2019, 03:25 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

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