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 = len(time)
print ( f"TASK\tPRIORITY\tTIME 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(len(priority)):
print(f"{i+1}\t{priority[i]}\t\t{time[i]}")
TASK PRIORITY TIME TO COMPLETE
1 2 30
2 6 200
3 1 20
4 7 70
5 10 120
6 8 60
7 5 150
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} at index {max_index}") # print out results in formatted statement
The maximum value is 11 at index 4
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 priority {max_value} at index {max_index}.")
print(f"The task time is {task_time} minutes.") # print out values as in Step #2 plus the time it takes to complete task
The maximum value is priority 11 at index 4.
The task time is 90 minutes.
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 priority {max_value} at index {max_index}.")
print(f"The task time is {task_time} minutes.")
#
# Add conditional to see if this task can be completed in the allotted time
if (time_used+task_time <= max_time):
print(f"Current time used is {time_used}.")
time_used += task_time
print(f"After completing task {max_index+1}, time used is now {time_used}.")
# if conditional is true, i.e., task can be completed update time_used
# add print statements
The maximum value is priority 11 at index 4.
The task time is 90 minutes.
Current time used is 180.
After completing task 5, time used is now 270.
# 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 = len(time)
print (f"TASK\tPRIORITY\tTIME TO COMPLETE")
for i in range(len(priority)):
print(f"{i+1}\t{priority[i]}\t\t{time[i]}")
# Initialize any variables before loop
max_time = 6 * 60
time_used = 0
# add for loop to go through all tasks
for tasks in range(n_tasks):
# find highest priority left and task number it corresponds to from Step 3/4
max_value = max(priority)
max_index = priority.index(max_value)
task_time = time_list[max_index]
# zero out this entry in the priority list so you won't find it again
priority.pop(priority.index(max_value))
# add conditional to check to see if task can be completed as in Step 4
if (time_used+task_time <= max_time):
print(f"Current time used is {time_used}.")
time_used += task_time
print(f"After completing task {max_index+1}, time used is now {time_used}.")
else:
print(f"There's not enough time for task {max_index+1}")
# Print out the total time used for all tasks in day 1
print(f"The total time used on day 1 is {time_used}.")
TASK PRIORITY TIME TO COMPLETE
1 2 30
2 6 200
3 1 20
4 7 70
5 10 120
6 8 60
7 5 150
Current time used is 0.
After completing task 5, time used is now 90.
The total time used on day 1 is 90.
Current time used is 90.
After completing task 5, time used is now 180.
The total time used on day 1 is 180.
Current time used is 180.
After completing task 4, time used is now 300.
The total time used on day 1 is 300.
Current time used is 300.
After completing task 2, time used is now 345.
The total time used on day 1 is 345.
There's not enough time for task 3
The total time used on day 1 is 345.
There's not enough time for task 1
The total time used on day 1 is 345.
There's not enough time for task 1
The total time used on day 1 is 345.
# 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 = len(time)
print (f"TASK\tPRIORITY\tTIME TO COMPLETE")
for i in range(len(priority)):
print(f"{i+1}\t{priority[i]}\t\t{time[i]}")
# Initialize any variables before loop
max_time = 6 * 60
time_used = 0
# add for loop to go through all tasks
for tasks in range(n_tasks):
# find highest priority left and task number it corresponds to from Step 3/4
max_value = max(priority)
max_index = priority.index(max_value)
task_time = time_list[max_index]
# zero out this entry in the priority list so you won't find it again
priority.pop(priority.index(max_value))
# add conditional to check to see if task can be completed as in Step 4
if (time_used+task_time < max_time):
time_used += task_time
print(f"After completing task {max_index+1}, time used is now {time_used}.")
elif (time_used+task_time == max_time):
# 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
break
else:
print(f"There's not enough time for task {max_index+1}")
# Print out the total time used for all tasks in day 1
print(f"The total time used on day 1 is {time_used}.")
TASK PRIORITY TIME TO COMPLETE
1 2 30
2 6 200
3 1 20
4 7 70
5 10 120
6 8 60
7 5 150
After completing task 5, time used is now 90.
The total time used on day 1 is 90.
After completing task 5, time used is now 180.
The total time used on day 1 is 180.
After completing task 4, time used is now 300.
The total time used on day 1 is 300.
After completing task 2, time used is now 345.
The total time used on day 1 is 345.
There's not enough time for task 3
The total time used on day 1 is 345.
There's not enough time for task 1
The total time used on day 1 is 345.
There's not enough time for task 1
The total time used on day 1 is 345.
# 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)
#
# 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
#
# use method .append() to create elements of the new priority list
#
for i in range(n_tasks):
priority.append(old_priority[i]/time[i])
print(f"{priority}")
# 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 = len(time)
print (f"TASK\tPRIORITY\tTIME TO COMPLETE")
for i in range(len(priority)):
print(f"{i+1}\t{priority[i]}\t\t{time[i]}")
# Initialize any variables before loop
max_time = 6 * 60
time_used = 0
# add for loop to go through all tasks
for tasks in range(n_tasks):
# find highest priority left and task number it corresponds to from Step 3/4
max_value = max(priority)
max_index = priority.index(max_value)
task_time = time_list[max_index]
# zero out this entry in the priority list so you won't find it again
priority.pop(priority.index(max_value))
# add conditional to check to see if task can be completed as in Step 4
if (time_used+task_time < max_time):
time_used += task_time
print(f"After completing task {max_index+1}, time used is now {time_used}.")
elif (time_used+task_time == max_time):
# 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
break
else:
print(f"There's not enough time for task {max_index+1}")
# Print out the total time used for all tasks in day 1
print(f"The total time used on day 1 is {time_used}.")
[0.06666666666666667, 0.03, 0.05, 0.1, 0.08333333333333333, 0.13333333333333333, 0.03333333333333333]
TASK PRIORITY TIME TO COMPLETE
1 0.06666666666666667 30
2 0.03 200
3 0.05 20
4 0.1 70
5 0.08333333333333333 120
6 0.13333333333333333 60
7 0.03333333333333333 150
After completing task 6, time used is now 70.
The total time used on day 1 is 70.
After completing task 4, time used is now 190.
The total time used on day 1 is 190.
After completing task 4, time used is now 310.
The total time used on day 1 is 310.
After completing task 1, time used is now 340.
The total time used on day 1 is 340.
There's not enough time for task 2
The total time used on day 1 is 340.
There's not enough time for task 2
The total time used on day 1 is 340.
There's not enough time for task 1
The total time used on day 1 is 340.