Day name program in python

In this program, we are going to print day name based on week no. Like – If the user enters 1 that means it is Monday.

Logic

After taking input (Week no) from the user, we have to compare that number with 1 to 7 or we can say comparing that number with a day of a week. So the logic goes like – if the number is equal to 1 then it is Monday, if the number is 2 then it is Tuesday etc… Like that we have to compare with each day of the week.

Program

# Taken day number from user
weekday = int(input("Enter weekday day number (1-7) : "))

if weekday == 1 :
    print("\nMonday");

elif weekday == 2 :
    print("\nTuesday")

elif(weekday == 3) :
    print("\nWednesday")

elif(weekday == 4) :
    print("\nThursday")

elif(weekday == 5) :
    print("\nFriday")

elif(weekday == 6) :
    print("\nSaturday")

elif (weekday == 7) :
    print("\nSunday")

else :
    print("\nPlease enter weekday number between 1-7.")

Output

Enter weekday day number (1-7) : 4
Thursday

Day name program in python
  • Home
  • PHP
  • MySQL
  • MongoDB
  • HTML
  • Javascript
  • Node.js
  • Express.js
  • Python
  • Jquery
  • R
  • Kotlin
  • DS
  • Blogs
  • Theory of Computation

In this post, you will learn how to write a Python program to input a week number and print the week day. For example, if the user enters 1, that implies it is Monday, and if the user enters 7, then the output should be Saturday.

To implement this, we need to take input from the user and store it in a variable. After taking input from the user, we have to compare that number with 1 to 7, or we can say, compare that number with a day of a week. So the logic goes like – if the number is equal to 1, then it is Monday, if the number is 2, then it is Tuesday; like that, we have to compare with each day of the week.

Python Program

The given Python program implements the above logic and prints the week day-

# Python program to input week number and print week day
weekday = int(input("Enter weekday number (1-7) : "))

if weekday == 1 :
    print("\nMonday");

elif weekday == 2 :
    print("\nTuesday")

elif(weekday == 3) :
    print("\nWednesday")

elif(weekday == 4) :
    print("\nThursday")

elif(weekday == 5) :
    print("\nFriday")

elif(weekday == 6) :
    print("\nSaturday")

elif (weekday == 7) :
    print("\nSunday")

else :
    print("\nPlease enter any weekday number (1-7)")

Output1:

Enter weekday number (1-7) : 5

Friday

Output2:

Enter weekday number (1-7) : 2

Tuesday

General Knowledge

Day name program in python

Day name program in python

Day name program in python

Day name program in python

Day name program in python

Day name program in python

Day name program in python

Day name program in python

Day name program in python

Day name program in python

Day name program in python

Day name program in python

Day name program in python

Day name program in python

Blogs

  • Jan 3

    Stateful vs Stateless

    A Stateful application recalls explicit subtleties of a client like profile, inclinations, and client activities...

  • Dec 29

    Best programming language to learn in 2021

    In this article, we have mentioned the analyzed results of the best programming language for 2021...

  • Dec 20

    How is Python best for mobile app development?

    Python has a set of useful Libraries and Packages that minimize the use of code...

  • July 18

    Learn all about Emoji

    In this article, we have mentioned all about emojis. It's invention, world emoji day, emojicode programming language and much more...

  • Jan 10

    Data Science Recruitment of Freshers

    In this article, we have mentioned about the recruitment of data science. Data Science is a buzz for every technician...

Follow us

Day name program in python

  • eTutorialsPoint©Copyright 2016-2022. All Rights Reserved.

How do I print the days of the week in Python?

Use the strftime() method of a datetime module to get the day's name in English in Python. It uses some standard directives to represent a datetime in a string format. The %A directive returns the full name of the weekday. Like, Monday, Tuesday.

How does Python define weekdays?

The weekday() method is used to returns the day of the week (0 is Monday) for year (1970–...), month (1–12), day (1–31). Year for which the calendar should be generated. month for which the calendar should be generated. day for which the calendar should be generated.

How do I print the day of the month in Python?

Suppose we have one year Y and a month M, we have to return the number of days of that month for the given year. So if the Y = 1992 and M = 7, then the result will be 31, if the year is 2020, and M = 2, then the result is 29.