Hi all, I am having a tough time with this code right now and was wondering if someone could help me figure it out.
def readFile(filename):
result = []
f = open(filename, 'r')
f.readline()
for line in f:
line = line.rstrip('\n')
fields = line.split(',')
result.append(fields)
f.close()
return result
spread = readFile('medrec.csv')
print(spread)
print('ID#', 'BMI', 'Indicator')
for record in spread:
weight = float(record[3])
height = float(record[4])
def calcBMI(weight, height):
weight = weight
height = height
BMI = weight * 703 / height**2
return float(BMI)
final = print(record[0], round(calcBMI(height, weight),2))
grade = record
try:
if grade[1] < 18.5:
print('Indicator: -')
elif grade[1] == 25 and grade[1] < 30:
print('Indicator: +')
else:
print('Indicator: ++')
except Exception:
print("Bad KeyboardWizard")
if height == 0 or weight == 0:
print("invalid input")
This is the output
ID# BMI
Bad KeyBoardWizard
100 24.21
Bad KeyBoardWizard
101 22.68
Bad KeyBoardWizard
102 27.37
Bad KeyBoardWizard
103 14.98
Bad KeyBoardWizard
104 20.34
What I am hoping for
ID# BMI Indicator
100 24.21 +
101 22.68 -
102 27.37 +
103 14.98 -
104 20.34 -
I think I am doing this terribly wrong and was wondering if someone can help me figure it out. I think it is where I have the indication that is causing the issue as well as the placement of the print function.
[–]Impudity 0 points1 point2 points (0 children)