validation for user input
This commit is contained in:
@@ -128,7 +128,16 @@ def print_webcomics(webcomics: Dict[str, Dict]) -> int:
|
|||||||
for index, entry in enumerate(webcomics["webcomics"]):
|
for index, entry in enumerate(webcomics["webcomics"]):
|
||||||
print(list_lines(index, entry["name"]))
|
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():
|
def webcomic_manager():
|
||||||
|
|||||||
Reference in New Issue
Block a user