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 task in range (0,n_tasks) :
print (f" {1 + task} {priority[task]} {time[task]}")
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"The maximum value is {max_value} and is located at index {max_index} which is the {max_index + 1}th item in the list.") # 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"The maximum value is {max_value} and is located at index {max_index} which is the {max_index + 1}th item in the list. This takes {task_time} minutes.")
# 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]
print(f"The maximum value is {max_value} and is located at index {max_index} which is the {max_index + 1}th item in the list. This takes {task_time} minutes.")
#
# Add conditional to see if this task can be completed in the allotted time
if (task_time < (max_time - time_used) ) :
time_used = time_used + task_time
print(f"Task {max_index + 1} can be completed with the remaining time. After this task is completed {time_used} minutes have been 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 ACTION CURRENT TIME USED CURRENT PRIORITY")
#
# Initialize any variables before loop
timeused = 0 #TimeCounter
totalpriority = 0 #PriorityCounterforComparisoninEvalQuestion
#
# add for loop to go through all tasks
# This loop will run n_tasks iterations in order of priority
for task in range(0, n_tasks) :
highestpriority = max(priority)
highestpriorityloc = priority.index(highestpriority)
highesttime = time[highestpriorityloc]
# Used to add the times in order of max priority
# We continue to add times when they are within 8 hrs or 480 min
if((timeused + highesttime) <= max_time) :
timeused = timeused + highesttime
totalpriority = totalpriority + highestpriority
# I did this to replicate the HW1 for ease of comparison
print(f"{task + 1} {highestpriority} {highesttime} Add {timeused} {totalpriority}")
# This sets the highestpriority equal to 0 for the next iteration in the loop to get the next highest tasked priority
priority[highestpriorityloc] = 0
# When the next highest priority task has a time that exceeds or max time we discard the item.
# Notice here that timeused nor totalpriority are being modified because they are not being used.
elif((timeused + highesttime) > max_time) :
print(f"{task + 1} {highestpriority} {highesttime} Discard {timeused} {totalpriority}")
priority[highestpriorityloc] = 0
# 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
timeused = 0 #TimeCounter
totalpriority = 0 #PriorityCounterforComparisoninEvalQuestion
#
# add for loop to go through all tasks
#
for task in range(0, n_tasks) :
if(timeused == max_time) :
break
highestpriority = max(priority)
highestpriorityloc = priority.index(highestpriority)
highesttime = time[highestpriorityloc]
# Used to add the times in order of max priority
# We continue to add times when they are within 8 hrs or 480 min
if((timeused + highesttime) <= max_time) :
timeused = timeused + highesttime
totalpriority = totalpriority + highestpriority
# Reformatted from question 5 for simplicity
print(f"{task + 1} {highestpriority} {highesttime}")
# This sets the highestpriority equal to 0 for the next iteration in the loop to get the next highest tasked priority
priority[highestpriorityloc] = 0
# When the next highest priority task has a time that exceeds or max time we discard the item.
elif((timeused + highesttime) > max_time) :
print(f"{task + 1} {highestpriority} {highesttime}")
priority[highestpriorityloc] = 0
#
# find highest priority left and task number it corresponds to from Step 3/4
#
# zero out this entry in the priority list so you won't find it again
#
# add conditional to check to see if task can be completed as in Step 4
# if this conditional is satisfied then add another conditional to check if time_used = max_time; if so break out of loop
#
# Print out the total time used for all tasks in day 1
# Input problem specific data
old_priority = [ 2, 6, 1, 7, 10, 8, 5]
time = [30,200,20,70,120,60, 150]
n_tasks = len(old_priority)
max_time = 8*60
#
# 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
# Setting value to a floating point variable to allow for decimals
value = 1.
for i in range(0, len(old_priority)) :
value = old_priority[i] / time[i]
value = round(value, 3)
priority.append(value)
# 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.
print (f"TASK PRIORITY RATIO TIME TO COMPLETE ACTION CURRENT TIME USED PRIORITY RATIO SUM")
#
# Initialize any variables before loop
timeused = 0 #TimeCounter
totalpriority = 0 #PriorityCounterforComparisoninEvalQuestion
#
# add for loop to go through all tasks
# This loop will run n_tasks iterations in order of priority
for task in range(0, n_tasks) :
highestpriority = max(priority)
highestpriorityloc = priority.index(highestpriority)
highesttime = time[highestpriorityloc]
# Used to add the times in order of max priority
# We continue to add times when they are within 8 hrs or 480 min
if((timeused + highesttime) <= max_time) :
timeused = timeused + highesttime
totalpriority = totalpriority + highestpriority
totalpriority = round(totalpriority,3)
# I did this to replicate the 5th question for ease of comparison
print(f"{task + 1} {highestpriority} {highesttime} Add {timeused} {totalpriority}")
# This sets the highestpriority equal to 0 for the next iteration in the loop to get the next highest tasked priority
priority[highestpriorityloc] = 0
# When the next highest priority task has a time that exceeds or max time we discard the item.
# Notice here that timeused nor totalpriority are being modified because they are not being used.
elif((timeused + highesttime) > max_time) :
print(f"{task + 1} {highestpriority} {highesttime} Discard {timeused} {totalpriority}")
priority[highestpriorityloc] = 0