Founding Batch Offer ยท HLD ยท LLD ยท System Design at โ‚น799 until 30 Nov

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.

IntermediatePhase 1 - Level 4: Logical Operators & Compound StatementsExample 8 of 10
weekday-or-weekend.py
1# Take day number
2day = int(input("Enter day number (1-7): "))
3
4# Check weekday or weekend
5if 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. 1

    Read the numbered weekday.

  2. 2

    Check one through five, then six or seven.

  3. 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.