This Python script prompts the user to enter a number between 1 and 7, using the match-case statement (similar to a switch-case) to display the corresponding day of the week. It includes input validation to handle incorrect or out-of-range inputs, providing a user-friendly experience.
- Match-Case Logic: Implements Python's
match-casestructure to map numbers to days. - Input Validation: Ensures user input is an integer within the specified range (1-7).
- Error Handling: Provides meaningful error messages for out-of-range or non-integer inputs.
- Run the script.
- Enter a number between 1 and 7 when prompted:
1-> Monday2-> Tuesday3-> Wednesday4-> Thursday5-> Friday6-> Saturday7-> Sunday
- If the input is valid, the program outputs the corresponding day of the week.
- If the input is out of range, an error message will prompt you to enter a number between 1 and 7.
- If the input is not an integer, an error message will prompt you to enter a valid integer.
Enter a number between 1 and 7: 3
Wednesday
Enter a number between 1 and 7: 10
Error: Please enter a number between 1 and 7.
Enter a number between 1 and 7: hello
Error: Invalid input. Please enter an integer.
Python 3.10+ (for match-case syntax)
This project is open source and available under the MIT License.