First implementation of the compiler
This commit is contained in:
0
Project-02-03/helpers/__init__.py
Normal file
0
Project-02-03/helpers/__init__.py
Normal file
22
Project-02-03/helpers/console.py
Normal file
22
Project-02-03/helpers/console.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from pathlib import Path
|
||||
|
||||
def prompt_choice(prompt: str, options: list) -> int:
|
||||
print(prompt)
|
||||
for i, opt in enumerate(options, 1):
|
||||
print(f" {i}. {opt}")
|
||||
|
||||
while True:
|
||||
try:
|
||||
s = input(f"Enter choice (1-{len(options)}): ").strip()
|
||||
idx = int(s) - 1
|
||||
if 0 <= idx < len(options):
|
||||
return idx
|
||||
except Exception:
|
||||
pass
|
||||
print(f"Invalid. Enter a number between 1-{len(options)}.")
|
||||
|
||||
def prompt_confirmation(question: str, default="y"):
|
||||
s = input(f"{question} (y/n) [{default}]: ").strip().lower()
|
||||
if not s:
|
||||
s = default
|
||||
return s.startswith("y")
|
||||
Reference in New Issue
Block a user