Skip to content

Commit 59378ad

Browse files
naoki1213mjCopilot
andcommitted
feat(book-app): add year range search to interactive menu
- Add "5. Search by year range" option to print_menu() - Update validate_menu_choice() to accept 1-6 (was 1-5) - Update get_user_choice() prompt to reflect new range - Move Exit to option 6 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 5ca4a1f commit 59378ad

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

samples/book-app-project/utils.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def print_menu() -> None:
1616
print("2. List books")
1717
print("3. Mark book as read")
1818
print("4. Remove a book")
19-
print("5. Exit")
19+
print("5. Search by year range")
20+
print("6. Exit")
2021

2122

2223
def print_books(books: list[Book]) -> None:
@@ -92,30 +93,30 @@ def validate_year_input(year_str: str) -> int:
9293

9394

9495
def validate_menu_choice(choice: str) -> None:
95-
"""Validate a menu choice is a digit between 1-5.
96+
"""Validate a menu choice is a digit between 1-6.
9697
9798
Raises:
9899
BookValidationError: If the choice is invalid.
99100
"""
100101
if not choice:
101-
raise BookValidationError("Input cannot be empty. Please enter a number between 1 and 5.")
102-
if not choice.isdigit() or not 1 <= int(choice) <= 5:
103-
raise BookValidationError(f"Invalid choice: '{choice}'. Please enter a number between 1 and 5.")
102+
raise BookValidationError("Input cannot be empty. Please enter a number between 1 and 6.")
103+
if not choice.isdigit() or not 1 <= int(choice) <= 6:
104+
raise BookValidationError(f"Invalid choice: '{choice}'. Please enter a number between 1 and 6.")
104105

105106

106107
# --- Input Functions (combine validation + display) ---
107108

108109

109110
def get_user_choice() -> str:
110-
"""Prompt the user to select a menu option (1-5) with validation.
111+
"""Prompt the user to select a menu option (1-6) with validation.
111112
112113
Used for the interactive menu mode (alternative to CLI arguments).
113114
114115
Returns:
115-
A string representing the user's valid choice ('1' through '5').
116+
A string representing the user's valid choice ('1' through '6').
116117
"""
117118
while True:
118-
choice = input("Choose an option (1-5): ").strip()
119+
choice = input("Choose an option (1-6): ").strip()
119120
try:
120121
validate_menu_choice(choice)
121122
except BookValidationError as e:

0 commit comments

Comments
 (0)