Weekday or Weekend
Separate weekdays from weekends using a numbered week in Python. Students combine a chained range check, an or condition, and a final invalid-value branch.
1# Take day number2day = int(input("Enter day number (1-7): "))34# Check weekday or weekend5if 1 <= day <= 5:6 print("Weekday")7elif day == 6 or day == 7:8 print("Weekend")9else:10 print("Invalid day")
Output
Enter day number (1-7): 3 Weekday Enter day number (1-7): 6 Weekend
In this one
- Group weekday numbers
- Use or for alternatives
- Reject invalid day numbers
How it works
- 1
Read the numbered weekday.
- 2
Check one through five, then six or seven.
- 3
Print the matched category or invalid feedback.
Edge cases
What happens for day 0?
What happens for day 0?
Invalid day is printed.
What happens for day 7?
What happens for day 7?
Weekend, because the second equality test succeeds.
What's going on
This exercise numbers Monday through Sunday as one through seven. The chained comparison groups the first five days without writing five separate equality checks.
If that interval fails, the next condition accepts either six or seven as Weekend. Anything else is invalid. Input 3 prints Weekday; 6 prints Weekend. The explicit final branch prevents out-of-range numbers from being treated as weekends.
What happens for day 0? Invalid day is printed.
What happens for day 7? Weekend, because the second equality test succeeds.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Why use or for days 6 and 7?
Pick an answer to check it.
Question 2
What happens for day 0?
Pick an answer to check it.
Questions people ask
What happens for day 0?
Invalid day is printed.
What happens for day 7?
Weekend, because the second equality test succeeds.
Why use or for days 6 and 7?
Either value should qualify.
๐Related Content
- ๐
Phase 1 - Learn Concepts
Review Phase 1 concepts and explanations
- ๐
Phase 1 - Quiz
Test your Phase 1 understanding with quiz questions
- ๐ป
Phase 1 - All Practice Problems
Explore all practice problems for Phase 1
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum