Skip to content

Commit

Permalink
Gracefully handles empty/non-integer input at menu (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xeno852 authored Mar 21, 2024
1 parent 6b94ab5 commit e1174fc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.9.7
29 changes: 21 additions & 8 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,29 @@
from classes.AFM import AffiliateMarketing

def main():
# Show user options
info("\n============ OPTIONS ============", False)

for idx, option in enumerate(OPTIONS):
print(colored(f" {idx + 1}. {option}", "cyan"))

info("=================================\n", False)

# Get user input
user_input = int(question("Select an option: "))
# user_input = int(question("Select an option: "))
valid_input = False
while not valid_input:
try:
# Show user options
info("\n============ OPTIONS ============", False)

for idx, option in enumerate(OPTIONS):
print(colored(f" {idx + 1}. {option}", "cyan"))

info("=================================\n", False)
user_input = input("Select an option: ").strip()
if user_input == '':
print("\n" * 100)
raise ValueError("Empty input is not allowed.")
user_input = int(user_input)
valid_input = True
except ValueError as e:
print("\n" * 100)
print(f"Invalid input: {e}")


# Start the selected option
if user_input == 1:
Expand Down

0 comments on commit e1174fc

Please sign in to comment.