Files
scripts_scad/utils.py
T

42 lines
1.1 KiB
Python

#!/bin/python3
from __future__ import annotations
def ask_int(prompt: str) -> int:
"""Prompt user for a positive integer."""
while True:
try:
value = int(input(prompt).strip())
if value <= 0:
print("Please enter a positive integer.")
continue
return value
except ValueError:
print("Please enter a valid integer.")
def ask_float(prompt: str) -> float:
"""Prompt user for a positive float."""
while True:
try:
value = float(input(prompt).strip())
if value <= 0:
print("Please enter a positive number.")
continue
return value
except ValueError:
print("Please enter a valid number.")
def ask_yes_no(prompt: str) -> bool:
"""Prompt the user for a yes/no answer."""
while True:
answer = input(prompt).strip().lower()
if answer in {"y", "yes"}:
return True
if answer in {"n", "no"}:
return False
print("Please enter yes or no. [y/n]")