-
Notifications
You must be signed in to change notification settings - Fork 0
/
DS_hw1
41 lines (28 loc) · 1.23 KB
/
DS_hw1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#-------------------
# define a function |
#-------------------
def check_blood_pressure(patients):
# Initialize variables to calculate the average
total_systolic = 0
total_diastolic = 0
num_patients = len(patients)
for name, systolic, diastolic in patients:
print(f"Name: {name}, Score 1: {systolic}, Score 2: {diastolic}")
total_systolic += systolic
total_diastolic += diastolic
if systolic >140 or diastolic>90:
print('Alert! Patient', name, 'may has a high blood pressure.')
else:
print('Patient', name, 'has a normal blood pressure.')
# Calculate averages
average_systolic = total_systolic / num_patients
average_diastolic = total_diastolic / num_patients
# Print average blood pressure
print(f"\nAverage Blood Pressure of this patient list: Systolic: {average_systolic:.2f}, Diastolic: {average_diastolic:.2f}")
# Print average blood pressure
print(f"\nAverage Blood Pressure of this patient list: Systolic: {average_systolic:.2f}, Diastolic: {average_diastolic:.2f}")
#-------------------
# try an example |
#-------------------
patients=[("John", 150, 95), ("Alice", 120, 80), ("Bob", 135, 88)]
check_blood_pressure(patients)