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.
1# Take day number2day = int(input("Enter day number (1-7): "))34# Print day name5if 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
Read day as an integer.
- 2
Compare it with each number one through seven.
- 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.
๐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