Skip to content

Commit 682515e

Browse files
committed
fixed menu
1 parent 990a74d commit 682515e

1 file changed

Lines changed: 31 additions & 44 deletions

File tree

classes/main.py

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
import os
77

88
test = i.SequenceTaker("temp")
9+
10+
911
def clear(): return os.system('cls' if os.name == 'nt' else 'clear')
1012

1113

1214
def menu():
13-
print("MENU: ")
14-
print()
15+
print('+-------------------------------------+')
16+
print('|--- *Page Replacement Simulation* ---|')
17+
print('+-------------------------------------+\n')
1518
print("[1] FIFO")
1619
print("[2] LRU")
1720
print("[3] LFU")
@@ -20,64 +23,48 @@ def menu():
2023
print()
2124

2225

23-
def fifo():
24-
if os.name != 'nt':
25-
test.retake_sequence(r"inputs/fifo.txt")
26-
else:
27-
test.retake_sequence(r"inputs\fifo.txt")
28-
fifo = f.FIFO(test.sequence, test.frames, test.process_count)
29-
30-
31-
def lru():
32-
if os.name != 'nt':
33-
test.retake_sequence(r"inputs/lru.txt")
34-
else:
35-
test.retake_sequence(r"inputs\lru.txt")
36-
lru = lr.LRU(test.sequence, test.frames, test.process_count)
37-
38-
39-
def lfu():
26+
def execute_algorithm(algorithm):
4027
if os.name != 'nt':
41-
test.retake_sequence(r"inputs/lfu.txt")
28+
test.retake_sequence(f"inputs/{algorithm.lower()}.txt")
4229
else:
43-
test.retake_sequence(r"inputs\lfu.txt")
44-
lfu = lf.LFU(test.sequence, test.frames, test.process_count)
30+
test.retake_sequence(f"inputs\\{algorithm.lower()}.txt")
4531

46-
47-
def optimal():
48-
if os.name != 'nt':
49-
test.retake_sequence(r"inputs/optimal.txt")
50-
else:
51-
test.retake_sequence(r"inputs\optimal.txt")
52-
opt = o.Optimal(test.sequence, test.frames, test.process_count)
32+
if algorithm == "FIFO":
33+
f.FIFO(test.sequence, test.frames, test.process_count)
34+
elif algorithm == "LRU":
35+
lr.LRU(test.sequence, test.frames, test.process_count)
36+
elif algorithm == "LFU":
37+
lf.LFU(test.sequence, test.frames, test.process_count)
38+
elif algorithm == "Optimal":
39+
o.Optimal(test.sequence, test.frames, test.process_count)
5340

5441

5542
def main():
56-
while (True):
43+
algorithms = {
44+
"1": "FIFO",
45+
"2": "LRU",
46+
"3": "LFU",
47+
"4": "Optimal"
48+
}
49+
50+
while True:
5751
menu()
5852
choice = input("Enter choice: ")
5953
print()
60-
if choice == "1":
61-
clear()
62-
fifo()
63-
elif choice == "2":
64-
clear()
65-
lru()
66-
elif choice == "3":
67-
clear()
68-
lfu()
69-
elif choice == "4":
70-
clear()
71-
optimal()
72-
elif choice == "0":
54+
55+
if choice == "0":
7356
clear()
7457
print("Exiting...")
7558
return
59+
60+
algorithm = algorithms.get(choice)
61+
if algorithm:
62+
clear()
63+
execute_algorithm(algorithm)
7664
else:
7765
clear()
7866
print("Invalid input. Please try again.")
7967
print()
80-
continue
8168

8269

8370
if __name__ == "__main__":

0 commit comments

Comments
 (0)