I'm having a little problem from my python code. This program is about process scheduling, which will get a user input of the number of processes, arrival time and burst time, but the requirement is to have a dynamic list (for the number of processes), and **get the user input of arrival and burst time like presented below.
I edited my previous post and removed all unnecessary codes to make the code more precised just for the problem.
Case 1: If I run the program with 4 processes:
Enter No. Of Processes: 4
Arrival Time:
P1: 0
P2: 2
P3: 4
P4: 5
Burst Time:
P1: 7
P2: 4
P3: 1
P4: 4
[1, 2, 3, 4, 0, 2, 4, 5, 7, 4, 1, 4] < ---- Output
From the output above I wanted to transform it like
[[1, 0, 7, 0], [2, 2, 4, 0], [3, 4, 1, 0], [4, 5, 4, 0]]
What I wanted is that the process data would be arranged in this way while still getting the inputs in for loop:
[process_id, arrival_time, burst_time, 0] -- I need to add a value of '0' for every end of a list
def initializeData(process_qty):
initialize_data = []
temporary = []
for i in range(process_qty):
process_id = i + 1
temporary.extend([process_id])
print("Arrival Time: ")
for i in range(process_qty):
arrival_time = int(input(" P" + str(i + 1) + ": "))
temporary.append(arrival_time)
print("Burst Time: ")
for i in range(process_qty):
burst_time = int(input(" P" + str(i + 1) + ": "))
temporary.append(burst_time)
initialize_data.extend(temporary)
print(initialize_data)
# I have good amounts functions and codes here
if __name__ == "__main__":
process_qty = int(input("Enter No. of Processes: "))
initializeData(process_qty)
Any suggestions guys? I am just learning python and happy about it!