https://github.com/anurag1101/match_case
"Python program demonstrating match-case usage for day selection. Prompts users to enter a number (1-7) and outputs the corresponding day, with input validation and error handling for non-integer and out-of-range inputs."
https://github.com/anurag1101/match_case
days-of-week match-case python python-3 python3 switch-case
Last synced: about 1 year ago
JSON representation
"Python program demonstrating match-case usage for day selection. Prompts users to enter a number (1-7) and outputs the corresponding day, with input validation and error handling for non-integer and out-of-range inputs."
- Host: GitHub
- URL: https://github.com/anurag1101/match_case
- Owner: Anurag1101
- Created: 2024-10-27T16:25:09.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-01-23T13:33:39.000Z (over 1 year ago)
- Last Synced: 2025-02-10T15:51:00.044Z (over 1 year ago)
- Topics: days-of-week, match-case, python, python-3, python3, switch-case
- Language: Python
- Homepage:
- Size: 106 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Day of the Week Program with Match-Case and Input Validation
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.
## Features
- **Match-Case Logic**: Implements Python's `match-case` structure 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.
## How to Use
1. Run the script.
2. Enter a number between 1 and 7 when prompted:
- `1` -> Monday
- `2` -> Tuesday
- `3` -> Wednesday
- `4` -> Thursday
- `5` -> Friday
- `6` -> Saturday
- `7` -> Sunday
3. If the input is valid, the program outputs the corresponding day of the week.
4. If the input is out of range, an error message will prompt you to enter a number between 1 and 7.
5. If the input is not an integer, an error message will prompt you to enter a valid integer.
## Example Output
### Valid Input
Enter a number between 1 and 7: 3
Wednesday
### Out-of-Range Input
Enter a number between 1 and 7: 10
Error: Please enter a number between 1 and 7.
### Non-Integer Input
Enter a number between 1 and 7: hello
Error: Invalid input. Please enter an integer.
### Requirements
Python 3.10+ (for match-case syntax)
### License
This project is open source and available under the MIT License.