This function calculates the average of the waiting & turnaround times Prints: Average Waiting time & Average Turn Around Time >>> calculate_average_times([0,3,5,0],[3,6,10,1],4) Average waiting time = 2.00000 Average turn around time = 5.0 >>> calculate_average_times([2,3],
(
waiting_time: list[int], turn_around_time: list[int], no_of_processes: int
)
| 93 | |
| 94 | |
| 95 | def calculate_average_times( |
| 96 | waiting_time: list[int], turn_around_time: list[int], no_of_processes: int |
| 97 | ) -> None: |
| 98 | """ |
| 99 | This function calculates the average of the waiting & turnaround times |
| 100 | Prints: Average Waiting time & Average Turn Around Time |
| 101 | >>> calculate_average_times([0,3,5,0],[3,6,10,1],4) |
| 102 | Average waiting time = 2.00000 |
| 103 | Average turn around time = 5.0 |
| 104 | >>> calculate_average_times([2,3],[3,6],2) |
| 105 | Average waiting time = 2.50000 |
| 106 | Average turn around time = 4.5 |
| 107 | >>> calculate_average_times([10,4,3],[2,7,6],3) |
| 108 | Average waiting time = 5.66667 |
| 109 | Average turn around time = 5.0 |
| 110 | """ |
| 111 | total_waiting_time = 0 |
| 112 | total_turn_around_time = 0 |
| 113 | for i in range(no_of_processes): |
| 114 | total_waiting_time = total_waiting_time + waiting_time[i] |
| 115 | total_turn_around_time = total_turn_around_time + turn_around_time[i] |
| 116 | print(f"Average waiting time = {total_waiting_time / no_of_processes:.5f}") |
| 117 | print("Average turn around time =", total_turn_around_time / no_of_processes) |
| 118 | |
| 119 | |
| 120 | if __name__ == "__main__": |