dimanche 20 septembre 2020

If Statement not functioning properly. Wrong branch is executing [closed]

I am writing a multi-sectional program for school. All other section work great except this one:

Systolic = int(input("What is your systolic reading? Enter numerical value only. "))  # Gather user's systolic reading
Treat2 = input('Are you currently being treated for high blood pressure? Type yes or no. ')
Treat = Treat2.strip()
# untreated
if Systolic < 120 and Treat == 'No' or Treat == 'no':
    Systolic_points = 0
if 120 <= Systolic <= 129 and Treat == 'No' or Treat == 'no':
    Systolic_points = 1
if 130 <= Systolic <= 139 and Treat == 'No' or Treat == 'no':
    Systolic_points = 2
if 140 <= Systolic <= 159:
    Systolic_points = 3
if Systolic >= 160:
    Systolic_points = 4
# treated
if Systolic < 120 and Treat == 'yes' or Treat == 'Yes':
    Systolic_points = 0
if 120 <= Systolic <= 129 and Treat == 'yes' or Treat == 'Yes':
    Systolic_points = 3
elif 130 <= Systolic <= 139 and Treat == 'yes' or Treat == 'Yes':
    Systolic_points = 4
elif 140 <= Systolic <= 159 and Treat == 'yes' or Treat == 'Yes':
    Systolic_points = 5
elif Systolic >= 160 and Treat == 'yes' or Treat == 'Yes':
    Systolic_points = 6

print('Systolic points =', Systolic_points)

For example, when entering 135 and Yes I receive that systolic points equal 3 when it should = 4. It seems that the if statements aren't executing. What is wrong with this section?

Aucun commentaire:

Enregistrer un commentaire