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 = max(time)
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" {task+1} {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 index of the max value in list is {max_index} and max is {test_list[max_index]}')
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 index of the max value in list is {max_index} and max is {test_list[max_index]} and takes {task_time} time to complete') # 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' the index of the max value in list is {max_index} and max is {test_list[max_index]} and takes {task_time} time to complete')
#
# 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' number {max_index +1} in list has been added and time used is now {time_used}')
else :
print (f' item number {max_index +1} went over the time limit ' )
# 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
# 480 minutes is equivalent to 8 hours which is our max time
max_value = max(priority)
max_index = priority.index(max_value)
task_time = time[max_index]
print ( f"TASK PRIORITY TIME TO COMPLETE")
for task in range (0, n_tasks):
print (f" {task+1} {priority[task]} {time[task]}")
#
# Initialize any variables before loop
time_used = 0
# time is initialized to zero because thats the value we are worried about going over
#
# add for loop to go through all tasks
#
for item in range (0, n_tasks) :
print ( ' **************************************************************************************')
max_value = max(priority)
max_index = priority.index(max_value)
task_time = time[max_index]
#the three lines above were repeated because it didnt work when i left them out
print (f'try task {max_index + 1}')
#loop created to only add times below the chosen max time
if ( (task_time + time_used) <= max_time ) :
print (f' task {max_index +1} in list has been added')
time_used = time_used + task_time
#since task was added time needs to be updated with the above formula
print (f' time used is {time_used}')
else :
print (f' task {max_index +1} went over the time limit ' )
priority[max_index] = 0
print ('***************************************************************************************')
print (f' sum of time of all tasks on day one is {time_used}' )
#
# 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
#
# Print out the total time used for all tasks in day 1
# 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
max_value = max(priority)
max_index = priority.index(max_value)
task_time = time[max_index]
print ( f"TASK PRIORITY TIME TO COMPLETE")
for task in range (0, n_tasks):
print (f" {task+1} {priority[task]} {time[task]}")
#
# Initialize any variables before loop
time_used = 0
#
# Initialize any variables before loop
#
# add for loop to go through all tasks
#
for item in range (0, n_tasks) :
print ( ' **************************************************************************************')
max_value = max(priority)
max_index = priority.index(max_value)
task_time = time[max_index]
#the three lines above were repeated because it didnt work when i left them out
print (f'try task {max_index + 1}')
#loop created to only add times below the chosen max time
if ( (task_time + time_used) <= max_time ) :
print (f' task {max_index +1} in list has been added')
time_used = time_used + task_time
print (f' time used is {time_used}')
if (time_used == max_time) :
break
else :
print (f' task {max_index +1} went over the time limit ' )
priority[max_index] = 0
print ('***************************************************************************************')
print (f' sum of time of all tasks on day one is {time_used}' )
#
# 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(time)
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
for i in range(n_tasks) :
p_ratios= old_priority[i]/ time[i]
priority.append(p_ratios)
# 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_value = max(priority)
max_index = priority.index(max_value)
task_time = time[max_index]
print ( f"TASK RATIO TIME TO COMPLETE")
for task in range (0, n_tasks):
print (f" {task+1} {priority[task]} {time[task]}")
#sorry i cant figure out how to cut off decimals after a certain point
time_used= 0
for item in range (0, n_tasks) :
print ( ' **************************************************************************************')
max_value = max(priority)
max_index = priority.index(max_value)
task_time = time[max_index]
print (f'try task {max_index + 1}')
if ( (task_time + time_used) <= max_time ) :
print (f' task {max_index +1} in list has been added')
time_used = time_used + task_time
print (f' time used is {time_used}')
if (time_used == max_time) :
break
else :
print (f' task {max_index +1} went over the time limit ' )
priority[max_index] = 0
print ('***************************************************************************************')
print (f' sum of time of all tasks on day one is {time_used}' )