priority = [ 2, 6, 1, 7, 10, 8, 5]
time = [30,200,20,70,120,60, 150]
#
# define number of tasks: don't hardwire this but rather use the len() command
n_tasks = len(priority)
max_time = 8*60
print ( f"TASK PRIORITY TIME TO COMPLETE")
# you need to add an appropriate for loop here and modify the next print statement so that you can print out all tasks
for i in range(n_tasks) :
print (f" {i+1} {priority[i]} {time[i]}")
test_list = [ 4, 5, 3, 7, 11, 2]
max_value = max(test_list) # use function max() to find maximum value in list
max_index = test_list.index(max_value) # use method list.index () to find the index where this max occurs
print (f'max value: {max_value} max index: {max_index}') # print out results in formatted statement
test_list = [ 4, 5, 3, 7, 11, 2]
time_list = [30, 45, 20, 120, 90, 70 ]
max_value = max(test_list)
max_index = test_list.index(max_value)
task_time = time_list[max_index] # input the time it takes to complete this task
print (f'max value: {max_value} max index: {max_index} task time: {task_time}') # print out values as in Step #2 plus the time it takes to complete task
max_time = 6 * 60 # this is not the maximum time available for your example but rather for testing
time_used = 3 * 60
#
# Following 6 statements are from Step 3
test_list = [ 4, 5, 3, 7, 11, 2]
time_list = [30, 45, 20, 120, 90, 70 ]
max_value = max(test_list)
max_index = test_list.index(max_value)
task_time = time_list[max_index] # input the time it takes to complete this task
print (f'max value: {max_value} max index: {max_index} task time: {task_time}')
#
# Add conditional to see if this task can be completed in the allotted time
if ( (time_used + task_time) <= max_time ) :
time_used+=task_time
print (f'task added: {max_index+1} time used: {time_used}')
# if conditional is true, i.e., task can be completed update time_used
# add print statements
# Input problem specific data and print it out from Step 1
priority = [ 2, 6, 1, 7, 10, 8, 5]
time = [30,200,20,70,120,60, 150]
n_tasks = len(priority)
max_time = 8*60
print ( f"TASK PRIORITY TIME TO COMPLETE")
# Initialize any variables before loop
time_used = 0
# add for loop to go through all tasks
for i in range(n_tasks) :
taskPriority = max(priority)
maxIndex = priority.index(taskPriority)
taskTime = time[maxIndex]
print (f" {maxIndex+1} {priority[maxIndex]} {time[maxIndex]}")
# zero out this entry in the priority list so you won't find it again
priority[maxIndex] = 0
# add conditional to check to see if task can be completed as in Step 4
if ((taskTime + time_used) <= max_time):
time_used += taskTime
# Print out the total time used for all tasks in day 1
print (f'time used on day 1: {time_used}')
# Input problem specific data and print it out from Step 1
priority = [ 2, 6, 1, 7, 10, 8, 5]
time = [30,200,20,70,120,60, 150]
n_tasks = len(priority)
max_time = 8*60
print ( f"TASK PRIORITY TIME TO COMPLETE")
# Initialize any variables before loop
time_used = 0
# add for loop to go through all tasks
for i in range(n_tasks) :
while (time_used < max_time):
taskPriority = max(priority)
maxIndex = priority.index(taskPriority)
taskTime = time[maxIndex]
print (f" {maxIndex+1} {priority[maxIndex]} {time[maxIndex]}")
# zero out this entry in the priority list so you won't find it again
priority[maxIndex] = 0
# add conditional to check to see if task can be completed as in Step 4
if ((taskTime + time_used) <= max_time):
time_used += taskTime
print (f'time used so far: {time_used}')
else:
print (f'time used so far: {time_used}')
break
# Print out the total time used for all tasks in day 1
print (f'time used on day 1: {time_used}')
# Input problem specific data
old_priority = [ 2, 6, 1, 7, 10, 8, 5]
time = [30,200,20,70,120,60, 150]
n_tasks = len(time)
# Create new priority list containing ratios
priority = [] # initialize the list which contains the new priorities which are original priority divided by
# time it takes to complete this task
# add for loop to create this list
for i in range(n_tasks):
ratio = old_priority[i]/time[i]
priority.append(ratio)
# use method .append() to create elements of the new priority list
# Remainder of code should be the same; this is because we called the new list which contained the ratios the same as
# before.
max_time = 8*60
print ( f"TASK PRIORITY TIME TO COMPLETE")
time_used = 0
for i in range(n_tasks) :
while (time_used < max_time):
taskPriority = max(priority)
maxIndex = priority.index(taskPriority)
taskTime = time[maxIndex]
if (taskPriority != 0):
print (f" {maxIndex+1} {priority[maxIndex]} {time[maxIndex]}")
priority[maxIndex] = 0
if ((taskTime + time_used) <= max_time and taskPriority != 0):
time_used += taskTime
print (f'time used on day 1: {time_used}')
else:
break
print (f'time used on day 1: {time_used}')