Day of Week From Number With Weekend Flag

Medium ⏱ 12 min 51% acceptance ★★★★★ 4.8
Write a function day_info(day_num) that takes an integer 1-7 (1=Monday ... 7=Sunday) and returns a tuple (day_name, is_weekend) where day_name is the English day name and is_weekend is True for Saturday/Sunday and False otherwise. Return ("Invalid", False) for any number outside 1-7.

Examples

Example 1
Input
day_info(6)
Output
("Saturday", True)
Explanation

6 maps to Saturday, a weekend day.

Example 2
Input
day_info(3)
Output
("Wednesday", False)
Explanation

3 maps to Wednesday, a weekday.

Example 3
Input
day_info(9)
Output
("Invalid", False)
Explanation

9 is outside the valid 1-7 range.

Constraints

  • day_num is an integer, possibly out of range.

Topics

Conditional Statementsif/elif/else

Companies

NetflixLinkedIn

Hints

Hint 1

A guard clause for out-of-range input should run before the main lookup.

Hint 2

is_weekend is True only when day_num is 6 or 7.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.