Nov-23-2019, 01:24 PM
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:
When I run framingham.py in the CLI, I get the following traceback:
Some help would be much appreciated. Thanks
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
