Created
September 30, 2025 13:05
-
-
Save thinkphp/f2bc96d49da4ecf17ca55925438810aa to your computer and use it in GitHub Desktop.
task1.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Task 1 - Main Menu for Tackle Hire System | |
| # Date: September 30, 2025 | |
| def display_menu(): | |
| """ | |
| Function to display the main menu options | |
| """ | |
| print("\n" + "="*50) | |
| print("TACKLE HIRE SYSTEM - MAIN MENU") | |
| print("="*50) | |
| print("1. Customer and hire details") | |
| print("2. Earnings report") | |
| print("3. Exit") | |
| print("="*50) | |
| def get_valid_option(): | |
| """ | |
| Function to get and validate user input for menu option | |
| Returns: Valid option (1, 2, or 3) | |
| """ | |
| while True: | |
| try: | |
| # Get user input | |
| option = input("\nPlease enter your choice (1-3): ") | |
| # Check if input is empty | |
| if option == "": | |
| print("Error: Input cannot be empty. Please try again.") | |
| continue | |
| # Convert to integer | |
| option_num = int(option) | |
| # Validate range | |
| if option_num < 1 or option_num > 3: | |
| print("Error: Invalid option. Please enter a number between 1 and 3.") | |
| continue | |
| # Return valid option | |
| return option_num | |
| except ValueError: | |
| # Handle non-numeric input | |
| print("Error: Invalid input. Please enter a number between 1 and 3.") | |
| def process_option(option): | |
| """ | |
| Function to process the selected menu option | |
| Parameters: option - the menu option selected (1, 2, or 3) | |
| Returns: True to continue loop, False to exit | |
| """ | |
| if option == 1: | |
| # Option 1 selected | |
| print("\n>>> Customer and hire details selected") | |
| return True | |
| elif option == 2: | |
| # Option 2 selected | |
| print("\n>>> Earnings report selected") | |
| return True | |
| elif option == 3: | |
| # Option 3 selected - Exit | |
| print("\n>>> Exiting the system...") | |
| print("Thank you for using the Tackle Hire System!") | |
| return False | |
| def main(): | |
| """ | |
| Main function to run the program | |
| """ | |
| print("\nWelcome to the Tackle Hire System!") | |
| # Main program loop | |
| continue_program = True | |
| while continue_program: | |
| # Display menu | |
| display_menu() | |
| # Get valid option from user | |
| option = get_valid_option() | |
| # Process the option and check if should continue | |
| continue_program = process_option(option) | |
| print("\nProgram terminated.\n") | |
| # Entry point of the program | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment