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

Print Day Name

Map a number from one through seven to a weekday name. A beginner Python walkthrough of equality tests, one selected branch, and an explicit invalid-input case.

IntermediatePhase 1 - Level 2: Nested If & Multiple ConditionsExample 9 of 10
print-day-name.py
1# Take day number
2day = int(input("Enter day number (1-7): "))
3
4# Print day name
5if day == 1:
6 print("Monday")
7elif day == 2:
8 print("Tuesday")
9elif day == 3:
10 print("Wednesday")
11elif day == 4:
12 print("Thursday")
13elif day == 5:
14 print("Friday")
15elif day == 6:
16 print("Saturday")
17elif day == 7:
18 print("Sunday")
19else:
20 print("Invalid day number")

Output

Enter day number (1-7): 3
Wednesday

Enter day number (1-7): 7
Sunday

In this one

  • Map integers to names
  • Use equality branches
  • Report invalid choices

How it works

  1. 1

    Read day as an integer.

  2. 2

    Compare it with each number one through seven.

  3. 3

    Print its name or Invalid day number.

Edge cases

What happens for 0?

What happens for 0?

The final branch prints Invalid day number.

Does 1 mean Sunday here?

Does 1 mean Sunday here?

No. This exercise explicitly maps 1 to Monday.

What's going on

This program uses Monday as day one and Sunday as day seven. The mapping is a convention chosen by the exercise; Python does not assign these numbers automatically.

The chain compares day with each integer in turn. Input 3 reaches Wednesday, while 7 reaches Sunday. A number outside the seven listed choices reaches the final else, which gives feedback instead of silently printing nothing.

What happens for 0? The final branch prints Invalid day number.

Does 1 mean Sunday here? No. This exercise explicitly maps 1 to Monday.

Quiz

Tap an option. The answer stays hidden until you pick.

Question 1

Which test selects Wednesday?

Pick an answer to check it.

Question 2

What happens for 0?

Pick an answer to check it.

Questions people ask

What happens for 0?

The final branch prints Invalid day number.

Does 1 mean Sunday here?

No. This exercise explicitly maps 1 to Monday.

Which test selects Wednesday?

day == 3.