Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.3 kB
5
Indexable
Never
#Past Exam Paper question 4

#define variables
readings = [0] * 7
days = 1
counter = 0

#User input blood sugar levels for 7 days
while counter < 7:
    readings[counter]=float(input('Enter for day ' + str(days) + ': ' ))
    counter += 1
    days += 1

#get highest
highest = readings[0]
counter = 1
while counter < 7:
    if readings[counter] > highest:
        highest = readings[counter]
    counter += 1

#get lowest
lowest = readings[0]
counter = 1
while counter < 7:
    if readings[counter] < lowest:
        lowest = readings[counter]
    counter += 1

#calculate moderated avarage
counter = 0
sugarSum = 0
while counter < 7:
    if readings[counter] != highest and readings[counter] != lowest:
        sugarSum += readings[counter]
    counter += 1   
modAvg = sugarSum/5

#decide which range
if modAvg <= 7:
    level = 'Ideal'
    recom = 'Congrats, your blood sugar level is normal'
elif 7 < modAvg <= 10:
    level = 'Optimal'
    recom = 'Keep it up'
elif 10 < modAvg <= 13:
    level = 'Suboptimal'
    recom = 'Consult doctor on dietary or medication modification'
else:
    level = 'Unacceptable'
    recom = 'Your condition requires immediate assistance'

#Display output
print('Your moderated avarage is ' + str(round(modAvg)) + '(' + level + ')')
print(recom)