-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem_menu.py
More file actions
38 lines (32 loc) · 1.34 KB
/
problem_menu.py
File metadata and controls
38 lines (32 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
class ProblemMenu:
@staticmethod
def list_problems():
problems = []
for difficulty in ["easy", "medium", "hard"]:
problem_files = [
f.replace(".py", "")
for f in os.listdir(f"problems/{difficulty}")
if f.endswith(".py")
]
problems.extend([(difficulty, prob) for prob in problem_files])
return problems
@staticmethod
def display_menu(problems):
os.system('clear' if os.name == 'posix' else 'cls') # if windows use cls
counts = {"easy": 0, "medium": 0, "hard": 0}
for difficulty, _ in problems:
counts[difficulty] += 1
print("\nSelect a problem to run:")
for i, (difficulty, problem) in enumerate(problems, 1):
if difficulty == "easy":
color = "\033[92m" # Green
elif difficulty == "medium":
color = "\033[93m" # Yellow
elif difficulty == "hard":
color = "\033[91m" # Red
else:
color = "\033[0m" # Default
print(f"{i}. {problem} ({color}{difficulty}\033[0m)")
print(f"\nTotal Problems: {len(problems)}")
print(f"Easy: \033[92m{counts['easy']}\033[0m, Medium: \033[93m{counts['medium']}\033[0m, Hard: \033[91m{counts['hard']}\033[0m")