From c9f8e8f6c4944af86052cf22f08aeba9f91f9319 Mon Sep 17 00:00:00 2001 From: Ekleen Kaur Date: Mon, 9 Jun 2025 13:42:04 +0000 Subject: [PATCH] fix: handle user-defined number of solutions --- search.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/search.py b/search.py index d04a509..da2abdc 100755 --- a/search.py +++ b/search.py @@ -15,8 +15,21 @@ print(stdout.decode('utf-8')) print(stderr.decode('utf-8')) - - pyoverflow3.submit_error(str(stderr),2) + try: + # Ask the user how many solutions they would like to see + num_solutions = int(input("How many solutions would you like to see? ")) + if num_solutions < 1 or num_solutions > 3: + # for out of range request, using default of 2 with a message + print("Please enter a number between 1 and 3. Using default value of 2.") + num_solutions = 2 + + except ValueError: + # catch block for non-integer input + print("Invalid input. Using default") + num_solutions = 2 + + pyoverflow3.submit_error(str(stderr), num_solutions) + except Exception as e: - print("QuickOverflow Error: " + e) \ No newline at end of file + print("QuickOverflow Error: " + e) \ No newline at end of file