table = []
with open('my BMI data.txt', 'r') as f:
# 读取文件,现在文件叫做f
i = 0
for line in f:
i = i + 1
if i == 1:
pass
else:
line = line.split()
SBP_DBP = line[4].split('/')
SBP = int(SBP_DBP[0])
DBP = int(SBP_DBP[1])
line.pop(4)
line.append(SBP)
line.append(DBP)
for x in range(5):
line[x] = float(line[x])
line.append(0)
line.append('a')
# line是一个列表
table.append(line)
table.insert(0, ['NO.', 'Sex', 'height', 'weight', 'SBP', 'DBP', 'BMI', 'Categories'])
for i in range(1, len(table)):
table[i][6] = table[i][3] / ((table[i][2]/100) ** 2)
if table[i][6] <= 18.5:
table[i][7] = 'Underweight'
if table[i][6] > 18.5 and table[i][6]<=24.9:
table[i][7] = 'Normal weight'
if table[i][6] > 24.9 and table[i][6]<=29.9:
table[i][7] = 'Overweight'
if table[i][6] >29.9:
table[i][7] = 'Obesity'
for i in range(len(table)):
print(table[i])
wyt 。。
最新推荐文章于 2024-11-09 20:38:27 发布