Dremendo Tag Line

Input day number and print day name in Python

if elif - Question 3

In this question, we will see how to input a number between 1 to 7 and print the corresponding day of a week (day name) in Python programming using the if elif statement. To know more about if elif statement click on the if elif statement lesson.

Q3) Write a program in Python to input a number between 1 to 7 and print the corresponding day of a week (day name).

Example:
1 = Sunday
2 = Monday
3 = Wednesday

Program

n=int(input('Enter a number '))

if n==1:
    print('Sunday')
elif n==2:
    print('Monday')
elif n==3:
    print('Tuesday')
elif n==4:
    print('Wednesday')
elif n==5:
    print('Thursday')
elif n==6:
    print('Friday')
elif n==7:
    print('Saturday')
else:
    print('Invalid number')

Output

Enter a number 5
Thursday
video-poster