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 = 480
print ( f"TASK PRIORITY TIME TO COMPLETE")
for task in range(0,n_tasks):
print (f" {task + 1 } {priority[ task ]} {time[ task ]}")
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 max value is : {max_value} the index is : {max_index}") # print out results in formatted statement
The max value is : 11 the index is : 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 max value is: {max_value} the index is: {max_index} and the max time it would take is {task_time}") # print out values as in Step #2 plus the time it takes to complete task
The max value is: 11 the index is: 4 and the max time it would take is 90
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 index of the max value in the list is: {max_index} and the max is: {test_list[max_index]} the max time it would take is: {task_time}")
if (task_time < (max_time - time_used) ) :
time_used = task_time + time_used
print (f" the {max_index + 1}th number in list was added and the time that is now used is {time_used}")
else:
print (f"item number {max_index + 1} is over the time limit")
the index of the max value in the list is: 4 and the max is: 11 the max time it would take is: 90
the 5th number in list was added and the time that is now used is 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 = 480
total_time = 0
renT = 0
print ( f"TASK PRIORITY TIME TO COMPLETE")
for task in range(0, n_tasks) :
maxP = max(priority)
time_index = priority.index(maxP)
tim = time[time_index]
total_time = total_time + tim
print (f" {task + 1} {maxP} {tim}")
if (renT + tim <= max_time):
print(f"Do task {task + 1} with the time of: {tim}")
renT = renT + tim
print(f"The time used on this task was {tim} with the priority as {maxP} and the time remaning after this task is {max_time - renT}")
else:
print (f"Task {task + 1} not completed in the given time")
priority [time_index] = 0
print (f"The total time used for all tasks: {total_time}")
TASK PRIORITY TIME TO COMPLETE
1 10 120
Do task 1 with the time of: 120
The time used on this task was 120 with the priority as 10 and the time remaning after this task is 360
2 8 60
Do task 2 with the time of: 60
The time used on this task was 60 with the priority as 8 and the time remaning after this task is 300
3 7 70
Do task 3 with the time of: 70
The time used on this task was 70 with the priority as 7 and the time remaning after this task is 230
4 6 200
Do task 4 with the time of: 200
The time used on this task was 200 with the priority as 6 and the time remaning after this task is 30
5 5 150
Task 5 not completed in the given time
6 2 30
Do task 6 with the time of: 30
The time used on this task was 30 with the priority as 2 and the time remaning after this task is 0
7 1 20
Task 7 not completed in the given time
The total time used for all tasks: 650
# 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 = 480
renT = 0
print ( f"TASK PRIORITY TIME TO COMPLETE")
#
for task in range(0, n_tasks) :
maxP = max(priority)
time_index = priority.index(maxP)
tim = time[time_index]
total_time = total_time + tim
print (f" {task + 1} {maxP} {tim}")
if (renT + tim <= max_time):
print(f"Do task {task + 1} with the time of: {tim}")
renT = renT + tim
print(f"The time that was used on this task is {tim} with the priority as {maxP} the time that is remaining after this task is {max_time - renT}")
if (renT ==max_time):
break
else:
print (f" task {task + 1} can not be finished in the given time")
priority [time_index]= 0
print (f" Total time for all of the tasks: {total_time}")
TASK PRIORITY TIME TO COMPLETE
1 10 120
Do task 1 with the time of: 120
The time that was used on this task is 120 with the priority as 10 the time that is remaining after this task is 360
task 1 can not be finished in the given time
2 8 60
Do task 2 with the time of: 60
The time that was used on this task is 60 with the priority as 8 the time that is remaining after this task is 300
task 2 can not be finished in the given time
3 7 70
Do task 3 with the time of: 70
The time that was used on this task is 70 with the priority as 7 the time that is remaining after this task is 230
task 3 can not be finished in the given time
4 6 200
Do task 4 with the time of: 200
The time that was used on this task is 200 with the priority as 6 the time that is remaining after this task is 30
task 4 can not be finished in the given time
5 5 150
6 5 150
7 5 150
Total time for all of the tasks: 1550
# Input problem specific data
old_priority = [ 2, 6, 1, 7, 10, 8, 5]
time = [30,200,20,70,120,60, 150]
# n_tasks = len(priority)
#
# Create new priority list containing ratios
#
priority = [time_index] # initialize the list which contains the new priorities which are original priority divided by
for i in range (n_tasks):
# add for loop to create this list
max_time:
# 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.
Execution error
IndentationError: expected an indented block (<ipython-input-7-6076442e18d8>, line 13)