Replymessage unavailable
کد پایتون
processes = []
n = int(input("Enter the number of processes: "))
for i in range(n):
process = []
process.append(input("Enter process name: "))
process.append(int(input("Enter arrival time: ")))
process.append(int(input("Enter burst time: ")))
processes.append(process)
# sort processes based on arrival time
processes.sort(key=lambda x: x[1])
# calculate waiting time and turnaround time
wt = [0] * n
tat = [0] * n
wt[0] = 0
tat[0] = processes[0][2]
for i in range(1, n):
wt[i] = wt[i-1] + processes[i-1][2]
tat[i] = tat[i-1] + processes[i][2] - processes[i][1]
# calculate average waiting time and turnaround time
avg_wt = sum(wt) / n
avg_tat = sum(tat) / n
# print results
print("Process\tArrival Time\tBurst Time\tWaiting Time\tTurnaround Time")
for i in range(n):
print(processes[i][0], "\t\t", processes[i][1], "\t\t", processes[i][2], "\t\t", wt[i], "\t\t", tat[i])
print("Average Waiting Time:", avg_wt)
print("Average Turnaround Time:", avg_tat)