validation for user input

This commit is contained in:
Danilo Reyes
2026-02-28 19:39:05 -06:00
parent f2d5c1324a
commit 12df61c524

View File

@@ -128,7 +128,16 @@ def print_webcomics(webcomics: Dict[str, Dict]) -> int:
for index, entry in enumerate(webcomics["webcomics"]):
print(list_lines(index, entry["name"]))
return int(input("Select a webcomic: "))
max_index = len(webcomics["webcomics"]) - 1
while True:
raw = input("Select a webcomic: ").strip()
if not raw.isdigit():
print("Please enter a number.")
continue
choice = int(raw)
if 0 <= choice <= max_index:
return choice
print(f"Please enter a number between 0 and {max_index}.")
def webcomic_manager():