Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 16 days 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 (19 days ago)
- Default Branch: master
- Last Pushed: 2024-10-27T16:34:21.000Z (19 days ago)
- Last Synced: 2024-10-27T19:30:00.936Z (19 days ago)
- Topics: days-of-week, match-case, python, python-3, python3, switch-case
- Language: Python
- Homepage:
- Size: 13.7 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: 3Wednesday
### 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.