Python program to find day of the week for a given date; Through this tutorial, i am going to show you how to find and display day of the week for a given date in python.
Python Program Find Day of Week For Given Date
- Algorithm to find day of the week or weekday for a given date
- Write a python program to find the day of the week for a given date and print weekday
Algorithm to find day of the week or weekday for a given date
- Import calendar module in the program.
- Take a date from the user in the form of date(d) – month(m) -year(y).
- Check the given date is valid or not.
- If the date is valid then execute the next statement in program.
- If date is invalid then show ‘you have entered an invalid date’ to the user.
- At the end of the program, Print the day of the week/weekday of the given date.
Write a python program to find the day of the week for a given date and print weekday
#Find the day of the week for a given date in Python # import calendar module import calendar d,m,y=map(int,input('Enter the value of date,month and year: ').split()) a=['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'] try: s=calendar.weekday(y,m,d) print('Weekday:',a[s]) except ValueError: print('You have entered an invalid date.')
Output
Enter the value of date,month and year: 05 04 2020 Weekday: Sunday
Recommended Python Tutorials
Recommended:-Python Program to Calculate Simple Interest
Recommended:-Python Program to Find Average of n Numbers
Recommended:-Python Program to ASCII Value of Character
Recommended:-Python Program to Calculate Compound Interest
Recommended:-Python Program to Check Leap Year
Recommended:-Python Program To Print Number Pattern
Recommended:-Python Program to Print Star Pattern
Recommended:-Python Program Calculate Sum of n Numbers
Recommended:-Python Program to Reverse Numbers
Recommended:-Python Program to Find Largest of n Numbers
Recommended:-Python Program to Find Power of Number
Recommended:-Python Program to Print Prime Number From 1 to N
Recommended:-Python Program to Find Square Root of Number
Recommended:-Python Program to Find Cube of Number
Recommended:-Python Palindrome Program