A typical workday is filled with interruptions. One might begin reading emails, and then realize that one has to respond to some of those emails, and then one's colleagues comes in to talk, but then someone's supervisor needs to have a word,... and so on. Each task is more important than the task before it (at least in this example), so a more recent task has to get finished before returning to a previous one. Once one is done talking to the supervisor one can return to the conversation with the colleague, and then finish up writing those emails, and finally finish reading one's email.
We can model a workday full of interruptions with a last in-first out data structure, a Stack.
Write a program workday.py
that goes through series of tasks maintained in a list. Each item in the list is actually a two-element sublist consisting of a task name and the number of minutes it will take to complete that task. For example, for me:
tasks = [ ['read work emails',10], \
['respond to emails', 10], \
['attend meeting', 15], \
['coffee break', 15], \
['talk to boss', 10], \
['read work emails',10], \
['respond to emails', 10], \
['conference call', 15], \
['conversation with colleague', 15], \
['coffee break', 15], \
['meet with student', 15] ]
And all of that is just for the three hours (180 minutes) of the morning!
In your program, write a while
loop that ticks through the workday, minute by minute:
clock = 0
while clock < WORKDAY_MINUTES:
.
.
.
Go through the tasks starting at the beginning, and working your way through them in order. Once a current_task
is completed, current_task
is (for the moment) set to None
.
There is a 1/10 chance every minute that the next task in the list will need to be started. If there is no current task being done, that task can be begun immediately, but it's possible that this next task will interrupt the current one before it has finished. In that case, your program should place current_task
onto a stack so that the next item can be addressed. It's entirely possible that this task, too, may be interrupted before completion. Only once any given current_task
is completed should the task that was previously interrupted (now stored on the stack) be popped off so that it can be continued.
------------
Current time is 14 and current task is None
Items on stack are: Stack[]
[Enter] to continue...
------------
Current time is 15 and current task is None
Items on stack are: Stack[]
New task coming in...!
[Enter] to continue...
------------
Current time is 16 and current task is ['respond to emails', 10]
Items on stack are: Stack[]
[Enter] to continue...
------------
Current time is 17 and current task is ['respond to emails', 9]
Items on stack are: Stack[]
[Enter] to continue...
------------
Current time is 18 and current task is ['respond to emails', 8]
Items on stack are: Stack[]
New task coming in...!
[Enter] to continue...
------------
Current time is 19 and current task is ['attend meeting', 15]
Items on stack are: Stack[['respond to emails', 7]]
[Enter] to continue...
------------
Current time is 20 and current task is ['attend meeting', 14]
Items on stack are: Stack[['respond to emails', 7]]
[Enter] to continue...
------------
Current time is 21 and current task is ['attend meeting', 13]
Items on stack are: Stack[['respond to emails', 7]]
[Enter] to continue...
------------
Current time is 22 and current task is ['attend meeting', 12]
Items on stack are: Stack[['respond to emails', 7]]
New task coming in...!
[Enter] to continue...
------------
Current time is 23 and current task is ['coffee break', 15]
Items on stack are: Stack[['respond to emails', 7],['attend meeting', 12]]
[Enter] to continue...
------------
Current time is 24 and current task is ['coffee break', 14]
Items on stack are: Stack[['respond to emails', 7],['attend meeting', 12]]
New task coming in...!
[Enter] to continue...
------------
Current time is 25 and current task is ['talk to boss', 10]
Items on stack are: Stack[['respond to emails', 7],['attend meeting', 12],['coffee break', 13]]
[Enter] to continue...
------------