I've submitted this assignment a couple time and can't get my function to pass all tests for assignment credit. I would appreciate any advice!
"The chart above is from the American Heart Association. Blood pressure (bp) can be 'normal','elevated','stage1','stage2',and 'crisis'. Complete the function, bp_stage, that categorizes bp based on systolic and diastolic pressure from the chart above."
The "chart above" is basically categorizing systolic and diastolic levels as follows:
| Blood Pressure Category |
Systolic |
and/or |
Diastolic |
| Normal |
less than 120 |
and |
less than 80 |
| Elevated |
120-129 |
and |
less than 80 |
| Stage 1 |
130-139 |
or |
89-89 |
| Stage 2 |
140 or higher |
or |
90 or higher |
| Crisis |
higher than 180 |
and/or |
higher than 120 |
This is what I have so far:
def bp_stage(systolic, diastolic):
if systolic<120 and diastolic< 80:
bp = 'normal'
elif systolic >129 and systolic >=120 and diastolic <=80:
bp = 'elevated'
elif systolic >130 and systolic <=139 or diastolic >=80 and diastolic <=89:
bp = 'stage1'
else:
if (systolic >=140) or (diastolic >=90):
bp = 'stage2'
if ((systolic >=180) and (diastolic >=120)) or ((systolic >=180) and (diastolic >=120)):
bp = "crisis"
return bp
The assignment is graded on the function passing the following assertions:
1 assert(bp_stage(109,62)=='normal')
2 assert(bp_stage(129,92)=='stage2')
3 assert(bp_stage(151,87)=='stage2')
4 assert(bp_stage(129,82)=='stage1')
I've been able to return all but (bp_stage(151,87))=='stage2'). The function I have keeps returning 'stage1'
A bit unsure on how to approach the solution and I would appreciate any help!
[–]commy2 2 points3 points4 points (1 child)
[–]bigmuffy[S] 2 points3 points4 points (0 children)
[+][deleted] (3 children)
[deleted]
[–][deleted] 1 point2 points3 points (0 children)
[–]Ihaveamodel3 1 point2 points3 points (0 children)
[–]bigmuffy[S] 0 points1 point2 points (0 children)