I am writing a program that sums the last 3 days of sick people

Viewed 29

I am writing a program that counts the number of sick people on a specific day that is the sum of the last 3 days combined and I get stuck once I get to day 4. the first 3 days were provided.

day_1 = 1
day_2 = 4
day_3 = 64
days = (day_1 + day_2 + day_3)
while(True):
    sick_count = int(input('OUTBREAK \n What day do you want a sick count for?: '))
    if sick_count == 1:
        print(f'Total: {day_1}')
    elif sick_count == 2:
        print(f'Total {day_2}')
    elif sick_count == 3:
        print(f'Total {day_3}')
    elif sick_count == 0:
        print('Sorry thats invalid')
    elif days > 3:
        sum()
1 Answers

Here is a way to handle this more generically. NOTE that I assume the user will enter day numbers starting with 1, NOT with 0. So, for the six day totals below, the valid days are 3, 4, 5 and 6.

sick = [1, 4, 64, 129, 322, 537]
while True:
    day = int(input('OUTBREAK \n What day do you want a sick count for?: '))
    if 3 <= day <= len(sick):
        print( "Three day total:", sum(sick[day-3:day]) )
    else:
        print( "Day out of range.")
Related